]> code.ossystems Code Review - openembedded-core.git/commitdiff
scripts: Fix encoding errors for python3
authorEd Bartosh <ed.bartosh@linux.intel.com>
Wed, 18 May 2016 18:57:23 +0000 (21:57 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 2 Jun 2016 07:10:03 +0000 (08:10 +0100)
Moved call of decode('utf-8') as close as possible to
call of subprocess API to avoid calling it in a lot of
other places.

Decoded binary data to utf-8 where appropriate to fix devtool
and recipetool tests in python 3 environment.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
meta/lib/oe/patch.py
scripts/lib/devtool/__init__.py
scripts/lib/recipetool/append.py
scripts/lib/recipetool/create.py
scripts/lib/recipetool/create_buildsys_python.py

index a25fd527f62661ddf9ba15d0d0ea6636cbadb75b..4a0d3f7149949d1dc947772e109d0d4cae0e7fe9 100644 (file)
@@ -292,7 +292,10 @@ class GitApplyTree(PatchTree):
     def decodeAuthor(line):
         from email.header import decode_header
         authorval = line.split(':', 1)[1].strip().replace('"', '')
-        return decode_header(authorval)[0][0]
+        result =  decode_header(authorval)[0][0]
+        if hasattr(result, 'decode'):
+            result = result.decode('utf-8')
+        return result
 
     @staticmethod
     def interpretPatchHeader(headerlines):
index 6f5bb8dba05e7fec3d0fe168f33eab9cdb7240bd..70053631e815dda297344afb7c2ef9b3c4b6d5a2 100644 (file)
@@ -69,6 +69,7 @@ def exec_watch(cmd, **options):
     buf = ''
     while True:
         out = process.stdout.read(1)
+        out = out.decode('utf-8')
         if out:
             sys.stdout.write(out)
             sys.stdout.flush()
index 35756b08afbafa3e1e27b3bf7ceb6239d6a3fbb8..5d73d307e040b9d2e9bcb59c648e682e5969a9d0 100644 (file)
@@ -90,7 +90,7 @@ def find_target_file(targetpath, d, pkglist=None):
                             if fnmatch.fnmatchcase(fullpth, targetpath):
                                 recipes[targetpath].append(pn)
                     elif line.startswith('pkg_preinst_') or line.startswith('pkg_postinst_'):
-                        scriptval = line.split(':', 1)[1].strip().decode('string_escape')
+                        scriptval = line.split(':', 1)[1].strip().encode('utf-8').decode('unicode_escape')
                         if 'update-alternatives --install %s ' % targetpath in scriptval:
                             recipes[targetpath].append('?%s' % pn)
                         elif targetpath_re.search(scriptval):
@@ -172,7 +172,7 @@ def get_source_path(cmdelements):
     """Find the source path specified within a command"""
     command = cmdelements[0]
     if command in ['install', 'cp']:
-        helptext = subprocess.check_output('LC_ALL=C %s --help' % command, shell=True)
+        helptext = subprocess.check_output('LC_ALL=C %s --help' % command, shell=True).decode('utf-8')
         argopts = ''
         argopt_line_re = re.compile('^-([a-zA-Z0-9]), --[a-z-]+=')
         for line in helptext.splitlines():
index e3e01e385a9dcfb382ba3c7995b88b1dc4b8af54..744ff1b0abde156083d90dbfaba54629eb9bd1b5 100644 (file)
@@ -851,14 +851,14 @@ def crunch_license(licfile):
                 continue
             # Squash spaces, and replace smart quotes, double quotes
             # and backticks with single quotes
-            line = oe.utils.squashspaces(line.strip()).decode("utf-8")
+            line = oe.utils.squashspaces(line.strip())
             line = line.replace(u"\u2018", "'").replace(u"\u2019", "'").replace(u"\u201c","'").replace(u"\u201d", "'").replace('"', '\'').replace('`', '\'')
             if line:
                 lictext.append(line)
 
     m = hashlib.md5()
     try:
-        m.update(' '.join(lictext))
+        m.update(' '.join(lictext).encode('utf-8'))
         md5val = m.hexdigest()
     except UnicodeEncodeError:
         md5val = None
index 5cbea2abbad1b3f9b322763eaa764dda019cbf0f..55cce0e942fb5c058af346c4cf50eeb50d4f09a4 100644 (file)
@@ -516,7 +516,7 @@ class PythonRecipeHandler(RecipeHandler):
         except (OSError, subprocess.CalledProcessError):
             pass
         else:
-            for line in dep_output.splitlines():
+            for line in dep_output.decode('utf-8').splitlines():
                 line = line.rstrip()
                 dep, filename = line.split('\t', 1)
                 if filename.endswith('/setup.py'):