[elbe-devel] [PATCH v2 3/5] Python3: change file() to open()

Bastian Germann bage at linutronix.de
Mon Jan 13 14:22:13 CET 2020


Am 13.12.19 um 12:45 schrieb Christian Teklenborg:
> 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>

Reviewed-by: Bastian Germann <bage at linutronix.de>

> ---
>  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 cbe07384..c654e410 100644
> --- a/elbepack/soapclient.py
> +++ b/elbepack/soapclient.py
> @@ -87,7 +87,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, "w")
>          part = 0
>  
>          # XXX the retry logic might get removed in the future, if the error
> @@ -641,7 +641,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)
> @@ -674,7 +674,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)
> @@ -729,7 +729,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)
> @@ -946,11 +946,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
> 



More information about the elbe-devel mailing list