All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 01/11] patman: Update cros_subprocess to use bytearray
Date: Sat, 11 May 2019 13:23:46 -0600	[thread overview]
Message-ID: <20190511192356.96651-2-sjg@chromium.org> (raw)
In-Reply-To: <20190511192356.96651-1-sjg@chromium.org>

At present this function uses lists and strings. This does not work so
well with Python 3, and testing against '' does not work for a bytearray.
Update the code to fix these issues.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/patman/cros_subprocess.py | 33 +++++++++++++++++++++------------
 tools/patman/gitutil.py         |  2 ++
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/tools/patman/cros_subprocess.py b/tools/patman/cros_subprocess.py
index ebd4300dfd..cd19150ee6 100644
--- a/tools/patman/cros_subprocess.py
+++ b/tools/patman/cros_subprocess.py
@@ -156,11 +156,11 @@ class Popen(subprocess.Popen):
                 self.stdin.close()
         if self.stdout:
             read_set.append(self.stdout)
-            stdout = []
+            stdout = bytearray()
         if self.stderr and self.stderr != self.stdout:
             read_set.append(self.stderr)
-            stderr = []
-        combined = []
+            stderr = bytearray()
+        combined = bytearray()
 
         input_offset = 0
         while read_set or write_set:
@@ -192,12 +192,12 @@ class Popen(subprocess.Popen):
                     data = os.read(self.stdout.fileno(), 1024)
                 except OSError:
                     pass
-                if data == "":
+                if not len(data):
                     self.stdout.close()
                     read_set.remove(self.stdout)
                 else:
-                    stdout.append(data)
-                    combined.append(data)
+                    stdout += data
+                    combined += data
                     if output:
                         output(sys.stdout, data)
             if self.stderr in rlist:
@@ -207,25 +207,34 @@ class Popen(subprocess.Popen):
                     data = os.read(self.stderr.fileno(), 1024)
                 except OSError:
                     pass
-                if data == "":
+                if not len(data):
                     self.stderr.close()
                     read_set.remove(self.stderr)
                 else:
-                    stderr.append(data)
-                    combined.append(data)
+                    stderr += data
+                    combined += data
                     if output:
                         output(sys.stderr, data)
 
         # All data exchanged.    Translate lists into strings.
         if stdout is not None:
-            stdout = ''.join(stdout)
+            try:
+                stdout = stdout.decode('utf-8')
+            except UnicodeDecodeError:
+                stdout = stdout.decode('utf-8', 'ignore')
         else:
             stdout = ''
         if stderr is not None:
-            stderr = ''.join(stderr)
+            try:
+                stderr = stderr.decode('utf-8')
+            except UnicodeDecodeError:
+                stderr = stderr.decode('utf-8', 'ignore')
         else:
             stderr = ''
-        combined = ''.join(combined)
+        try:
+            combined = combined.decode('utf-8')
+        except UnicodeDecodeError:
+            combined = combined.decode('utf-8', 'ignore')
 
         # Translate newlines, if requested.    We cannot let the file
         # object do the translation: It is based on stdio, which is
diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py
index 9905bb0bbd..7650b51bd5 100644
--- a/tools/patman/gitutil.py
+++ b/tools/patman/gitutil.py
@@ -326,6 +326,8 @@ def BuildEmailList(in_list, tag=None, alias=None, raise_on_error=True):
     result = []
     for item in raw:
         if not item in result:
+            if type(item) == unicode:
+                item = item.encode('utf-8')
             result.append(item)
     if tag:
         return ['%s %s%s%s' % (tag, quote, email, quote) for email in result]
-- 
2.21.0.1020.gf2820cf01a-goog

  reply	other threads:[~2019-05-11 19:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-11 19:23 [U-Boot] [PATCH 00/11] dm: Removal of some boards due to DM_MMC deadline Simon Glass
2019-05-11 19:23 ` Simon Glass [this message]
2019-05-11 19:23 ` [U-Boot] [PATCH 02/11] Add a simple script to remove boards Simon Glass
2019-05-11 19:44   ` Tom Rini
2019-05-12 19:03     ` Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 03/11] solidrun: Fix soldrun typo Simon Glass
2019-05-12 10:00   ` Stefan Roese
2019-05-11 19:23 ` [U-Boot] [PATCH 04/11] atmel: gurnard: Complete DM migration Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 05/11] bubblegum_96: " Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 06/11] arm: Remove s32v234evb board Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 07/11] arm: Remove ls1088ardb_sdcard_qspi_SECURE_BOOT board Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 08/11] arm: Remove ls1046ardb_sdcard_SECURE_BOOT board Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 09/11] arm: Remove ls1043ardb_sdcard_SECURE_BOOT board Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 10/11] evb-ast2500: Enable CONFIG_DM_MMC Simon Glass
2019-05-13 16:39   ` Maxim Sloyko
2019-05-11 19:23 ` [U-Boot] [PATCH 11/11] vf610twr/_nand: " Simon Glass
2019-05-11 19:36 ` [U-Boot] [PATCH 00/11] dm: Removal of some boards due to DM_MMC deadline Tom Rini
2019-05-12 19:03   ` Simon Glass
2019-05-12 20:08     ` Simon Glass
2019-05-14 14:08       ` Tom Rini
2019-05-14 14:11     ` Tom Rini

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=20190511192356.96651-2-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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.