summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool
diff options
context:
space:
mode:
authorJiajie Hu <jiajie.hu@intel.com>2016-11-11 14:02:18 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-11-23 11:10:15 +0000
commitbfd8c35c3f917e3806c8dfe36c98c70fbccbb3c9 (patch)
tree9cde5f577c39bcd4be1b9e216811cbb1b2691df2 /scripts/lib/devtool
parent8c84830fa14a6e18daba37d18b41671f42d4f4fb (diff)
downloadpoky-bfd8c35c3f917e3806c8dfe36c98c70fbccbb3c9.tar.gz
devtool: fix handling of unicode characters from subprocess stdout
In previous implementation, a UnicodeDecodeError exception will be raised if multi-byte encoded characters are printed by the subprocess. As an example, the following command will fail in an en_US.UTF-8 environment because wget quotes its saving destination with '‘'(0xE2 0x80 0x98), while just the first byte is provided for decoding: devtool add recipe http://example.com/source.tar.xz The patch fixes the issue by avoiding such kind of incomplete decoding. (From OE-Core rev: 1875ea92546d23abcab1b40b562477a0016f712d) Signed-off-by: Jiajie Hu <jiajie.hu@intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/devtool')
-rw-r--r--scripts/lib/devtool/__init__.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/scripts/lib/devtool/__init__.py b/scripts/lib/devtool/__init__.py
index e675133f63..31ecb65937 100644
--- a/scripts/lib/devtool/__init__.py
+++ b/scripts/lib/devtool/__init__.py
@@ -23,6 +23,7 @@ import sys
23import subprocess 23import subprocess
24import logging 24import logging
25import re 25import re
26import codecs
26 27
27logger = logging.getLogger('devtool') 28logger = logging.getLogger('devtool')
28 29
@@ -67,10 +68,10 @@ def exec_watch(cmd, **options):
67 cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **options 68 cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **options
68 ) 69 )
69 70
71 reader = codecs.getreader('utf-8')(process.stdout)
70 buf = '' 72 buf = ''
71 while True: 73 while True:
72 out = process.stdout.read(1) 74 out = reader.read(1, 1)
73 out = out.decode('utf-8')
74 if out: 75 if out:
75 sys.stdout.write(out) 76 sys.stdout.write(out)
76 sys.stdout.flush() 77 sys.stdout.flush()