Răsfoiți Sursa

HUE-8737 [core] app_reg open file issue for py3

Ying Chen 6 ani în urmă
părinte
comite
7d72b25c5f
2 a modificat fișierele cu 14 adăugiri și 2 ștergeri
  1. 6 0
      tools/app_reg/app_reg.py
  2. 8 2
      tools/app_reg/registry.py

+ 6 - 0
tools/app_reg/app_reg.py

@@ -95,6 +95,12 @@ def get_app_info(app_loc):
     res = popen.wait()
     stdout, stderr = popen.communicate()
     # Cmd failure?
+
+    if isinstance(stdout, bytes):
+      stdout = stdout.decode('utf-8')
+    if isinstance(stderr, bytes):
+      stderr = stderr.decode('utf-8')
+
     if res != 0:
       LOG.error("Error getting application info from %s:\n%s" % (app_loc, stderr))
       raise OSError(stderr)

+ 8 - 2
tools/app_reg/registry.py

@@ -49,7 +49,10 @@ class AppRegistry(object):
   def _open(self):
     """Open the registry file. May raise OSError"""
     if os.path.exists(self._reg_path):
-      reg_file = file(self._reg_path)
+      if sys.version_info[0] > 2:
+        reg_file = open(self._reg_path)
+      else:
+        reg_file = file(self._reg_path)
       app_list = json.load(reg_file)
       reg_file.close()
 
@@ -62,7 +65,10 @@ class AppRegistry(object):
 
   def _write(self, path):
     """Write out the registry to the given path"""
-    outfile = file(path, 'w')
+    if sys.version_info[0] > 2:
+      outfile = open(path, 'w')
+    else:
+      outfile = file(path, 'w')
     json.dump(list(self._apps.values()), outfile, cls=AppJsonEncoder, indent=2)
     outfile.close()