All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 13/22] scripts: Fix encoding errors for python3
Date: Wed,  1 Jun 2016 13:35:31 +0100	[thread overview]
Message-ID: <1464784540-2786-13-git-send-email-richard.purdie@linuxfoundation.org> (raw)
In-Reply-To: <1464784540-2786-1-git-send-email-richard.purdie@linuxfoundation.org>

From: Ed Bartosh <ed.bartosh@linux.intel.com>

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>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/lib/oe/patch.py                             | 5 ++++-
 scripts/lib/devtool/__init__.py                  | 1 +
 scripts/lib/recipetool/append.py                 | 4 ++--
 scripts/lib/recipetool/create.py                 | 4 ++--
 scripts/lib/recipetool/create_buildsys_python.py | 2 +-
 5 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index a25fd52..4a0d3f7 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -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):
diff --git a/scripts/lib/devtool/__init__.py b/scripts/lib/devtool/__init__.py
index 6f5bb8d..7005363 100644
--- a/scripts/lib/devtool/__init__.py
+++ b/scripts/lib/devtool/__init__.py
@@ -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()
diff --git a/scripts/lib/recipetool/append.py b/scripts/lib/recipetool/append.py
index 35756b08..5d73d30 100644
--- a/scripts/lib/recipetool/append.py
+++ b/scripts/lib/recipetool/append.py
@@ -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():
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py
index e3e01e3..744ff1b 100644
--- a/scripts/lib/recipetool/create.py
+++ b/scripts/lib/recipetool/create.py
@@ -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
diff --git a/scripts/lib/recipetool/create_buildsys_python.py b/scripts/lib/recipetool/create_buildsys_python.py
index 5cbea2a..55cce0e 100644
--- a/scripts/lib/recipetool/create_buildsys_python.py
+++ b/scripts/lib/recipetool/create_buildsys_python.py
@@ -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'):
-- 
2.5.0



  parent reply	other threads:[~2016-06-01 12:35 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-01 12:35 [PATCH 01/22] oe-buildenv-internal: Update to python3 Richard Purdie
2016-06-01 12:35 ` [PATCH 02/22] classes/lib: Convert to use python3 octal syntax Richard Purdie
2016-06-01 21:57   ` Christopher Larson
2016-06-02  7:11     ` Richard Purdie
2016-06-01 12:35 ` [PATCH 03/22] classes/lib: Update to use python3 command pipeline decoding Richard Purdie
2016-06-01 12:35 ` [PATCH 04/22] classes/lib: Update to match python3 iter requirements Richard Purdie
2016-06-01 12:35 ` [PATCH 05/22] classes/lib: Update to explictly create lists where needed Richard Purdie
2016-06-01 12:35 ` [PATCH 06/22] classes/lib: Update xrange -> range for python3 Richard Purdie
2016-06-01 12:35 ` [PATCH 07/22] sanity: Switch urlparse to urllib.parse Richard Purdie
2016-06-01 12:35 ` [PATCH 08/22] wic: use python3 in shebang Richard Purdie
2016-06-01 12:35 ` [PATCH 09/22] wic: encode help text Richard Purdie
2016-06-01 12:35 ` [PATCH 10/22] qemurunner: convert data when working with socket Richard Purdie
2016-06-01 12:35 ` [PATCH 11/22] scripts: Fix deprecated dict methods for python3 Richard Purdie
2016-06-01 12:35 ` [PATCH 12/22] scripts: Replace basestring -> str " Richard Purdie
2016-06-01 12:35 ` Richard Purdie [this message]
2016-06-01 12:35 ` [PATCH 14/22] scripts: Rename ConfigParser -> configparser " Richard Purdie
2016-06-01 12:35 ` [PATCH 15/22] scripts: Fix urlparse imports " Richard Purdie
2016-06-01 12:35 ` [PATCH 16/22] scripts: use python3 in shebang Richard Purdie
2016-06-01 12:35 ` [PATCH 17/22] classes/lib: Complete transition to python3 Richard Purdie
2016-06-01 12:35 ` [PATCH 18/22] selftest/devtool: Compare sets instead of arrays on AssertEqual Richard Purdie
2016-06-01 12:35 ` [PATCH 19/22] buildhistory_analysis: Convert stream data (bytes) to strings Richard Purdie
2016-06-01 12:35 ` [PATCH 20/22] devtool.py: Fix parsing of bitbake-layers' output Richard Purdie
2016-06-01 15:38   ` Christopher Larson
2016-06-01 12:35 ` [PATCH 21/22] oeqa/selftest/recipetool.py: Use regex to match warning line Richard Purdie
2016-06-01 12:35 ` [PATCH 22/22] qemurunner: Use surrogateescape decoding Richard Purdie
2016-06-01 15:20 ` [PATCH 01/22] oe-buildenv-internal: Update to python3 Randle, William C
2016-06-01 15:35 ` Christopher Larson
2016-06-01 20:57   ` Richard Purdie
2016-06-01 20:59     ` Christopher Larson
2016-06-02  7:31 ` Python3 for bitbake/OE merged Richard Purdie
2016-06-02 15:23   ` Christopher Larson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1464784540-2786-13-git-send-email-richard.purdie@linuxfoundation.org \
    --to=richard.purdie@linuxfoundation.org \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.