mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 23:24:38 +00:00
patman: Update cros_subprocess to use bytes
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>
This commit is contained in:
parent
ef8b7e045e
commit
b1793a531e
2 changed files with 29 additions and 20 deletions
|
@ -100,6 +100,19 @@ class Popen(subprocess.Popen):
|
||||||
if kwargs:
|
if kwargs:
|
||||||
raise ValueError("Unit tests do not test extra args - please add tests")
|
raise ValueError("Unit tests do not test extra args - please add tests")
|
||||||
|
|
||||||
|
def ConvertData(self, data):
|
||||||
|
"""Convert stdout/stderr data to the correct format for output
|
||||||
|
|
||||||
|
Args:
|
||||||
|
data: Data to convert, or None for ''
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Converted data, as bytes
|
||||||
|
"""
|
||||||
|
if data is None:
|
||||||
|
return b''
|
||||||
|
return data
|
||||||
|
|
||||||
def CommunicateFilter(self, output):
|
def CommunicateFilter(self, output):
|
||||||
"""Interact with process: Read data from stdout and stderr.
|
"""Interact with process: Read data from stdout and stderr.
|
||||||
|
|
||||||
|
@ -156,11 +169,11 @@ class Popen(subprocess.Popen):
|
||||||
self.stdin.close()
|
self.stdin.close()
|
||||||
if self.stdout:
|
if self.stdout:
|
||||||
read_set.append(self.stdout)
|
read_set.append(self.stdout)
|
||||||
stdout = []
|
stdout = b''
|
||||||
if self.stderr and self.stderr != self.stdout:
|
if self.stderr and self.stderr != self.stdout:
|
||||||
read_set.append(self.stderr)
|
read_set.append(self.stderr)
|
||||||
stderr = []
|
stderr = b''
|
||||||
combined = []
|
combined = b''
|
||||||
|
|
||||||
input_offset = 0
|
input_offset = 0
|
||||||
while read_set or write_set:
|
while read_set or write_set:
|
||||||
|
@ -186,46 +199,40 @@ class Popen(subprocess.Popen):
|
||||||
write_set.remove(self.stdin)
|
write_set.remove(self.stdin)
|
||||||
|
|
||||||
if self.stdout in rlist:
|
if self.stdout in rlist:
|
||||||
data = ""
|
data = b''
|
||||||
# We will get an error on read if the pty is closed
|
# We will get an error on read if the pty is closed
|
||||||
try:
|
try:
|
||||||
data = os.read(self.stdout.fileno(), 1024)
|
data = os.read(self.stdout.fileno(), 1024)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
if data == "":
|
if not len(data):
|
||||||
self.stdout.close()
|
self.stdout.close()
|
||||||
read_set.remove(self.stdout)
|
read_set.remove(self.stdout)
|
||||||
else:
|
else:
|
||||||
stdout.append(data)
|
stdout += data
|
||||||
combined.append(data)
|
combined += data
|
||||||
if output:
|
if output:
|
||||||
output(sys.stdout, data)
|
output(sys.stdout, data)
|
||||||
if self.stderr in rlist:
|
if self.stderr in rlist:
|
||||||
data = ""
|
data = b''
|
||||||
# We will get an error on read if the pty is closed
|
# We will get an error on read if the pty is closed
|
||||||
try:
|
try:
|
||||||
data = os.read(self.stderr.fileno(), 1024)
|
data = os.read(self.stderr.fileno(), 1024)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
if data == "":
|
if not len(data):
|
||||||
self.stderr.close()
|
self.stderr.close()
|
||||||
read_set.remove(self.stderr)
|
read_set.remove(self.stderr)
|
||||||
else:
|
else:
|
||||||
stderr.append(data)
|
stderr += data
|
||||||
combined.append(data)
|
combined += data
|
||||||
if output:
|
if output:
|
||||||
output(sys.stderr, data)
|
output(sys.stderr, data)
|
||||||
|
|
||||||
# All data exchanged. Translate lists into strings.
|
# All data exchanged. Translate lists into strings.
|
||||||
if stdout is not None:
|
stdout = self.ConvertData(stdout)
|
||||||
stdout = ''.join(stdout)
|
stderr = self.ConvertData(stderr)
|
||||||
else:
|
combined = self.ConvertData(combined)
|
||||||
stdout = ''
|
|
||||||
if stderr is not None:
|
|
||||||
stderr = ''.join(stderr)
|
|
||||||
else:
|
|
||||||
stderr = ''
|
|
||||||
combined = ''.join(combined)
|
|
||||||
|
|
||||||
# Translate newlines, if requested. We cannot let the file
|
# Translate newlines, if requested. We cannot let the file
|
||||||
# object do the translation: It is based on stdio, which is
|
# object do the translation: It is based on stdio, which is
|
||||||
|
|
|
@ -326,6 +326,8 @@ def BuildEmailList(in_list, tag=None, alias=None, raise_on_error=True):
|
||||||
result = []
|
result = []
|
||||||
for item in raw:
|
for item in raw:
|
||||||
if not item in result:
|
if not item in result:
|
||||||
|
if type(item) == unicode:
|
||||||
|
item = item.encode('utf-8')
|
||||||
result.append(item)
|
result.append(item)
|
||||||
if tag:
|
if tag:
|
||||||
return ['%s %s%s%s' % (tag, quote, email, quote) for email in result]
|
return ['%s %s%s%s' % (tag, quote, email, quote) for email in result]
|
||||||
|
|
Loading…
Reference in a new issue