[elbe-devel] [PATCH 3/5] Python3: change file() to open()
Torben Hohn
torben.hohn at linutronix.de
Fri Dec 6 16:02:59 CET 2019
On Fri, Dec 06, 2019 at 02:08:47PM +0100, Christian Teklenborg wrote:
> Since Python3 there is no file() function anymore.
> To make Elbe Python2 and Python3 compatible, change every 'file()' to 'open()'.
>
> Signed-off-by: Christian Teklenborg <chris at linutronix.de>
see inline...
> ---
> elbepack/archivedir.py | 2 +-
> elbepack/commands/get_archive.py | 2 +-
> elbepack/commands/setsel.py | 2 +-
> elbepack/debpkg.py | 2 +-
> elbepack/soapclient.py | 12 ++++++------
> 5 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/elbepack/archivedir.py b/elbepack/archivedir.py
> index 8ad4d8d0..fcff1088 100644
> --- a/elbepack/archivedir.py
> +++ b/elbepack/archivedir.py
> @@ -27,7 +27,7 @@ class ArchivedirError(Exception):
> pass
>
> def enbase(fname, compress=True):
> - infile = file(fname, "r")
> + infile = open(fname, "r")
> s = infile.read()
> if compress:
> s = bz2compress(s)
> diff --git a/elbepack/commands/get_archive.py b/elbepack/commands/get_archive.py
> index 2dd4ecc9..6ce7cbc1 100644
> --- a/elbepack/commands/get_archive.py
> +++ b/elbepack/commands/get_archive.py
> @@ -16,7 +16,7 @@ from elbepack.treeutils import etree
>
>
> def unbase(s, fname):
> - outfile = file(fname, "w")
> + outfile = open(fname, "w")
> outfile.write(standard_b64decode(s))
> outfile.close()
>
> diff --git a/elbepack/commands/setsel.py b/elbepack/commands/setsel.py
> index 141b05b1..2ff653de 100644
> --- a/elbepack/commands/setsel.py
> +++ b/elbepack/commands/setsel.py
> @@ -14,7 +14,7 @@ from elbepack.treeutils import etree
>
>
> def parse_selections(fname):
> - fp = file(fname, "r")
> + fp = open(fname, "r")
>
> sels = []
>
> diff --git a/elbepack/debpkg.py b/elbepack/debpkg.py
> index ede724cc..a6c58531 100644
> --- a/elbepack/debpkg.py
> +++ b/elbepack/debpkg.py
> @@ -34,7 +34,7 @@ def gen_controlfile(name, version, arch, description, deps):
>
>
> def write_file(fname, mode, cont):
> - f = file(fname, "w")
> + f = open(fname, "w")
> f.write(cont)
> f.close()
> os.chmod(fname, mode)
> diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
> index 51cd474f..62324cd0 100644
> --- a/elbepack/soapclient.py
> +++ b/elbepack/soapclient.py
> @@ -88,7 +88,7 @@ class ElbeSoapClient(object):
> self.service.login(user, passwd)
>
> def download_file(self, builddir, filename, dst_fname):
> - fp = file(dst_fname, "w")
> + fp = open(dst_fname, "wb")
why are you changing "w" to "wb" here ?
and not at the other points ?
should this change be necessary, please split it out into a separate
patch, and explain it in the commitlog.
> part = 0
>
> # XXX the retry logic might get removed in the future, if the error
> @@ -642,7 +642,7 @@ class SetCdromAction(ClientAction):
> builddir = args[0]
> filename = args[1]
>
> - fp = file(filename, "r")
> + fp = open(filename, "r")
> client.service.start_cdrom(builddir)
> while True:
> bindata = fp.read(size)
> @@ -675,7 +675,7 @@ class SetOrigAction(ClientAction):
> builddir = args[0]
> filename = args[1]
>
> - fp = file(filename, "r")
> + fp = open(filename, "r")
> client.service.start_upload_orig(builddir, os.path.basename(filename))
> while True:
> bindata = fp.read(size)
> @@ -730,7 +730,7 @@ class SetPdebuilderAction(ClientAction):
> builddir = args[0]
> filename = args[1]
>
> - fp = file(filename, "r")
> + fp = open(filename, "r")
> client.service.start_pdebuild(builddir)
> while True:
> bindata = fp.read(size)
> @@ -947,11 +947,11 @@ class UploadPackageAction(RepoAction):
>
> # Parse .dsc-File and append neccessary source files to files
> if filetype == '.dsc':
> - for f in deb822.Dsc(file(filename))['Files']:
> + for f in deb822.Dsc(open(filename))['Files']:
> files.append(f['name'])
>
> if filetype == '.changes':
> - for f in deb822.Changes(file(filename))['Files']:
> + for f in deb822.Changes(open(filename))['Files']:
> files.append(f['name'])
>
> # Check whether all files are available
> --
> 2.20.1
>
>
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel
--
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
Hinweise zum Datenschutz finden Sie hier (Informations on data privacy
can be found here): https://linutronix.de/kontakt/Datenschutz.php
Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen |
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner
More information about the elbe-devel
mailing list