]> code.ossystems Code Review - openembedded-core.git/commitdiff
meta/scripts: python3: rename file -> open
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 21 May 2016 11:26:45 +0000 (12:26 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 21 May 2016 21:26:25 +0000 (22:26 +0100)
file() API doesn't exist in python 3, convert to open(). Also handle
some cases where files aren't closed. Compatible with python 2.7.

[Contributions from Ed and Richard]

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/insane.bbclass
meta/lib/oe/qa.py
meta/lib/oe/tests/test_path.py
meta/recipes-devtools/apt/apt-native.inc
scripts/contrib/python/generate-manifest-2.7.py
scripts/contrib/python/generate-manifest-3.5.py
scripts/swabber-strace-attach

index 0b151c214d7e868f6126d11531ffcaad56f24bc2..116abc428bb761e26cc9adb3957ccc0d0244ad8f 100644 (file)
@@ -177,9 +177,8 @@ def package_qa_write_error(type, error, d):
     logfile = d.getVar('QA_LOGFILE', True)
     if logfile:
         p = d.getVar('P', True)
-        f = file( logfile, "a+")
-        print >> f, "%s: %s [%s]" % (p, error, type)
-        f.close()
+        with open(logfile, "a+") as f:
+            f.write("%s: %s [%s]" % (p, error, type))
 
 def package_qa_handle_error(error_class, error_msg, d):
     package_qa_write_error(error_class, error_msg, d)
index cc2902f4affb61c4ff244b38285c0eaf43907f39..2c301419b0b7a0616b1548e004934cc53658bcc7 100644 (file)
@@ -43,9 +43,9 @@ class ELFFile:
         if not os.path.isfile(self.name):
             raise NotELFFileError("%s is not a normal file" % self.name)
 
-        self.file = file(self.name, "r")
-        # Read 4k which should cover most of the headers we're after
-        self.data = self.file.read(4096)
+        with open(self.name, "rb") as f:
+            # Read 4k which should cover most of the headers we're after
+            self.data = f.read(4096)
 
         if len(self.data) < ELFFile.EI_NIDENT + 4:
             raise NotELFFileError("%s is not an ELF" % self.name)
index 3d41ce157aed31700c684aeaf92df8ac0693f446..5fa24483d1be4a37be5dc906c719d80af8d8e419 100644 (file)
@@ -55,7 +55,7 @@ class TestRealPath(unittest.TestCase):
         for d in self.DIRS:
             os.mkdir(os.path.join(self.root, d))
         for f in self.FILES:
-            file(os.path.join(self.root, f), "w")
+            open(os.path.join(self.root, f), "w")
         for l in self.LINKS:
             os.symlink(l[1], os.path.join(self.root, l[0]))
 
index 27cc9ff0b55cc31ea4a8b227f4fdc3a62555af00..59aa04e119be51c378c1ae5f1f22d14541f0c3ad 100644 (file)
@@ -18,7 +18,7 @@ python do_install () {
 
 python do_install_config () {
     indir = os.path.dirname(d.getVar('FILE',1))
-    infile = file(oe.path.join(indir, 'files', 'apt.conf'), 'r')
+    infile = open(oe.path.join(indir, 'files', 'apt.conf'), 'r')
     data = infile.read()
     infile.close()
 
@@ -30,7 +30,7 @@ python do_install_config () {
 
     outpath = oe.path.join(outdir, 'apt.conf.sample')
     if not os.path.exists(outpath):
-        outfile = file(outpath, 'w')
+        outfile = open(outpath, 'w')
         outfile.write(data)
         outfile.close()
 }
index d93c943c61d7f920215011a5bd6872d220134915..48be3a6d74a928b3201c59c34a3a2827ca15c64d 100755 (executable)
@@ -153,7 +153,7 @@ if __name__ == "__main__":
             os.unlink(sys.argv[1])
         except Exception:
             sys.exc_clear()
-        outfile = file( sys.argv[1], "w" )
+        outfile = open( sys.argv[1], "w" )
     else:
         outfile = sys.stdout
 
index 367b4b8b4b6826997f7af474649b7efdec4b8798..a7b38d202a271adebd5c9ffb562263693fc4fdd7 100755 (executable)
@@ -156,7 +156,7 @@ if __name__ == "__main__":
             os.unlink(sys.argv[1])
         except Exception:
             sys.exc_clear()
-        outfile = file( sys.argv[1], "w" )
+        outfile = open( sys.argv[1], "w" )
     else:
         outfile = sys.stdout
 
index bb0391a7cadebf86a9e1652cd539cf4ae2916044..f258987d5ea5f7a9e582f9a38e45e2d829e51d04 100755 (executable)
@@ -16,8 +16,8 @@ else:
     sys.exit()
 
 
-si = file(os.devnull, 'r')
-so = file(sys.argv[2], 'w')
+si = open(os.devnull, 'r')
+so = open(sys.argv[2], 'w')
 se = so
 
 # Replace those fds with our own