python: Switch to using open instead of file
authorAndreas Sandberg <andreas.sandberg@arm.com>
Fri, 25 Jan 2019 12:03:21 +0000 (12:03 +0000)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Tue, 12 Feb 2019 16:44:21 +0000 (16:44 +0000)
Python 3 doesn't support the file(name, mode) syntax which has been
deprecated in favour of open.

Change-Id: I35ef8690d97a5243860a64ff985fd22fa86253f1
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/15985
Reviewed-by: Gabe Black <gabeblack@google.com>
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
src/python/importer.py
src/python/m5/main.py
src/python/m5/simulate.py
src/python/m5/util/code_formatter.py
src/python/m5/util/grammar.py

index 60b9b35cd144fccd8941a64a3cefd1fb3b987253..c54fb49570f5b4d616453faadd29476f01e56dbc 100644 (file)
@@ -67,7 +67,7 @@ class CodeImporter(object):
 
             override = os.environ.get('M5_OVERRIDE_PY_SOURCE', 'false').lower()
             if override in ('true', 'yes') and  os.path.exists(abspath):
-                src = file(abspath, 'r').read()
+                src = open(abspath, 'r').read()
                 code = compile(src, abspath, 'exec')
 
             if os.path.basename(srcfile) == '__init__.py':
index d8c0d923bee123680b7737f3a05841fbfa9deeb4..e4619c09dac20a4c64b7831b22d90abee35f54d7 100644 (file)
@@ -407,7 +407,7 @@ def main(*args):
     sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path
 
     filename = sys.argv[0]
-    filedata = file(filename, 'r').read()
+    filedata = open(filename, 'r').read()
     filecode = compile(filedata, filename, 'exec')
     scope = { '__file__' : filename,
               '__name__' : '__m5_main__' }
index 03cc253e98874baee0738e2b81fbcc84ad10e88f..d72dee22217c70ee685f62fef7d0776628f3d9f1 100644 (file)
@@ -92,7 +92,7 @@ def instantiate(ckpt_dir=None):
     for obj in root.descendants(): obj.unproxyParams()
 
     if options.dump_config:
-        ini_file = file(os.path.join(options.outdir, options.dump_config), 'w')
+        ini_file = open(os.path.join(options.outdir, options.dump_config), 'w')
         # Print ini sections in sorted order for easier diffing
         for obj in sorted(root.descendants(), key=lambda o: o.path()):
             obj.print_ini(ini_file)
@@ -101,7 +101,8 @@ def instantiate(ckpt_dir=None):
     if options.json_config:
         try:
             import json
-            json_file = file(os.path.join(options.outdir, options.json_config), 'w')
+            json_file = open(
+                os.path.join(options.outdir, options.json_config), 'w')
             d = root.get_config_as_dict()
             json.dump(d, json_file, indent=4)
             json_file.close()
index d48c59b261aa862cc460bea5cc4aaa8f88bcb49f..129fbd0e3c5b6b5eb1019c09304383826d0b7b25 100644 (file)
@@ -154,7 +154,7 @@ class code_formatter(object):
         self._data = []
 
     def write(self, *args):
-        f = file(os.path.join(*args), "w")
+        f = open(os.path.join(*args), "w")
         for data in self._data:
             f.write(data)
         f.close()
index bb3429866f24178b0db9e49b8c7ebab686d958f8..fcd8df2c9d5b14c21760574e3305619e9a443f8b 100644 (file)
@@ -115,7 +115,7 @@ class Grammar(object):
     def parse_file(self, f, **kwargs):
         if isinstance(f, basestring):
             source = f
-            f = file(f, 'r')
+            f = open(f, 'r')
         elif isinstance(f, file):
             source = f.name
         else: