[elbe-devel] [PATCH 2/3] repomanager: use open() instead of file()

Torben Hohn torben.hohn at linutronix.de
Wed Sep 30 15:06:17 CEST 2020


file() does not exist anymore in python3. And the with statement
should be used.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/repomanager.py | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/elbepack/repomanager.py b/elbepack/repomanager.py
index 485b9c2b0..9586af4df 100644
--- a/elbepack/repomanager.py
+++ b/elbepack/repomanager.py
@@ -280,22 +280,24 @@ class RepoBase(object):
 
     def removesrc(self, path, components=None):
         # pylint: disable=undefined-variable
-        for p in Deb822.iter_paragraphs(file(path)):
-            if 'Source' in p:
-                self._removesrc(p['Source'],
-                                self.repo_attr.codename,
-                                components)
+        with open(path) as fp:
+            for p in Deb822.iter_paragraphs(fp):
+                if 'Source' in p:
+                    self._removesrc(p['Source'],
+                                    self.repo_attr.codename,
+                                    components)
 
     def _remove(self, path, codename, components=None):
         # pylint: disable=undefined-variable
-        for p in Deb822.iter_paragraphs(file(path)):
-            if 'Source' in p:
-                self._removesrc(p['Source'], codename, components)
-            elif 'Package' in p:
-                self._removedeb(p['Package'], codename, components)
-            elif 'Binary' in p:
-                for pp in p['Binary'].split():
-                    self._removedeb(pp, codename, components)
+        with open(path) as fp:
+            for p in Deb822.iter_paragraphs(fp):
+                if 'Source' in p:
+                    self._removesrc(p['Source'], codename, components)
+                elif 'Package' in p:
+                    self._removedeb(p['Package'], codename, components)
+                elif 'Binary' in p:
+                    for pp in p['Binary'].split():
+                        self._removedeb(pp, codename, components)
 
 
     def _includedsc(self, path, codename, components=None):
-- 
2.20.1



More information about the elbe-devel mailing list