Browse Source

HUE-8737 [core] Fix desktop log open file and conf bytes issue

Ying Chen 6 years ago
parent
commit
f58252c459
2 changed files with 8 additions and 1 deletions
  1. 5 0
      desktop/core/src/desktop/lib/conf.py
  2. 3 1
      desktop/core/src/desktop/log/__init__.py

+ 5 - 0
desktop/core/src/desktop/lib/conf.py

@@ -720,6 +720,11 @@ def coerce_password_from_script(script):
   p = subprocess.Popen(script, shell=True, stdout=subprocess.PIPE)
   stdout, stderr = p.communicate()
 
+  if isinstance(stdout, bytes):
+    stdout = stdout.decode('utf-8')
+  if isinstance(stderr, bytes):
+    stderr = stderr.decode('utf-8')
+
   if p.returncode != 0:
     if stderr:
       LOG.error("Failed to read password from script:\n%s" % stderr)

+ 3 - 1
desktop/core/src/desktop/log/__init__.py

@@ -35,8 +35,10 @@ from desktop.log.formatter import MessageOnlyFormatter
 
 if sys.version_info[0] > 2:
   from io import StringIO as string_io
+  open_file = open
 else:
   from cStringIO import StringIO as string_io
+  open_file = file
 
 DEFAULT_LOG_DIR = 'logs'
 LOG_FORMAT = '[%(asctime)s] %(module)-12s %(levelname)-8s %(message)s'
@@ -65,7 +67,7 @@ def _read_log_conf(proc_name, log_dir):
     return None
 
   try:
-    raw = file(log_conf).read()
+    raw = open_file(log_conf).read()
     sio = string_io(CONF_RE.sub(_repl, raw))
     return sio
   except IOError as ex: