mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 10:10:46 +00:00
Add a fallback for sys.stdout.encoding uses
In some environments (e.g. nosetest), sys.stdout.encoding can be None. Add a fallback to handle these cases.
This commit is contained in:
parent
d86d67f49c
commit
5d97c3186b
@ -112,7 +112,7 @@ class AcmeCapeInstrument(Instrument):
|
|||||||
raise HostError(msg.format(output))
|
raise HostError(msg.format(output))
|
||||||
if self.process.returncode != 15: # iio-capture exits with 15 when killed
|
if self.process.returncode != 15: # iio-capture exits with 15 when killed
|
||||||
if sys.version_info[0] == 3:
|
if sys.version_info[0] == 3:
|
||||||
output += self.process.stdout.read().decode(sys.stdout.encoding, 'replace')
|
output += self.process.stdout.read().decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||||
else:
|
else:
|
||||||
output += self.process.stdout.read()
|
output += self.process.stdout.read()
|
||||||
self.logger.info('ACME instrument encountered an error, '
|
self.logger.info('ACME instrument encountered an error, '
|
||||||
|
@ -82,8 +82,8 @@ class EnergyProbeInstrument(Instrument):
|
|||||||
if self.process.returncode is not None:
|
if self.process.returncode is not None:
|
||||||
stdout, stderr = self.process.communicate()
|
stdout, stderr = self.process.communicate()
|
||||||
if sys.version_info[0] == 3:
|
if sys.version_info[0] == 3:
|
||||||
stdout = stdout.decode(sys.stdout.encoding, 'replace')
|
stdout = stdout.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||||
stderr = stderr.decode(sys.stdout.encoding, 'replace')
|
stderr = stderr.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||||
raise HostError(
|
raise HostError(
|
||||||
'Energy Probe: Caiman exited unexpectedly with exit code {}.\n'
|
'Energy Probe: Caiman exited unexpectedly with exit code {}.\n'
|
||||||
'stdout:\n{}\nstderr:\n{}'.format(self.process.returncode,
|
'stdout:\n{}\nstderr:\n{}'.format(self.process.returncode,
|
||||||
|
@ -101,8 +101,8 @@ class MonsoonInstrument(Instrument):
|
|||||||
if process.returncode is not None:
|
if process.returncode is not None:
|
||||||
stdout, stderr = process.communicate()
|
stdout, stderr = process.communicate()
|
||||||
if sys.version_info[0] == 3:
|
if sys.version_info[0] == 3:
|
||||||
stdout = stdout.encode(sys.stdout.encoding)
|
stdout = stdout.encode(sys.stdout.encoding or 'utf-8')
|
||||||
stderr = stderr.encode(sys.stdout.encoding)
|
stderr = stderr.encode(sys.stdout.encoding or 'utf-8')
|
||||||
raise HostError(
|
raise HostError(
|
||||||
'Monsoon script exited unexpectedly with exit code {}.\n'
|
'Monsoon script exited unexpectedly with exit code {}.\n'
|
||||||
'stdout:\n{}\nstderr:\n{}'.format(process.returncode,
|
'stdout:\n{}\nstderr:\n{}'.format(process.returncode,
|
||||||
|
@ -281,7 +281,7 @@ class FtraceCollector(TraceCollector):
|
|||||||
process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True)
|
process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True)
|
||||||
_, error = process.communicate()
|
_, error = process.communicate()
|
||||||
if sys.version_info[0] == 3:
|
if sys.version_info[0] == 3:
|
||||||
error = error.decode(sys.stdout.encoding, 'replace')
|
error = error.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||||
if process.returncode:
|
if process.returncode:
|
||||||
raise TargetStableError('trace-cmd returned non-zero exit code {}'.format(process.returncode))
|
raise TargetStableError('trace-cmd returned non-zero exit code {}'.format(process.returncode))
|
||||||
if error:
|
if error:
|
||||||
|
@ -152,7 +152,7 @@ class ApkInfo(object):
|
|||||||
try:
|
try:
|
||||||
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
|
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
|
||||||
if sys.version_info[0] == 3:
|
if sys.version_info[0] == 3:
|
||||||
output = output.decode(sys.stdout.encoding, 'replace')
|
output = output.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise HostError('Error parsing APK file {}. `aapt` says:\n{}'
|
raise HostError('Error parsing APK file {}. `aapt` says:\n{}'
|
||||||
.format(apk_path, e.output))
|
.format(apk_path, e.output))
|
||||||
|
@ -280,7 +280,7 @@ class SshConnection(object):
|
|||||||
# the regex removes line breaks potential introduced when writing
|
# the regex removes line breaks potential introduced when writing
|
||||||
# command to shell.
|
# command to shell.
|
||||||
if sys.version_info[0] == 3:
|
if sys.version_info[0] == 3:
|
||||||
output = process_backspaces(self.conn.before.decode(sys.stdout.encoding, 'replace'))
|
output = process_backspaces(self.conn.before.decode(sys.stdout.encoding or 'utf-8', 'replace'))
|
||||||
else:
|
else:
|
||||||
output = process_backspaces(self.conn.before)
|
output = process_backspaces(self.conn.before)
|
||||||
output = re.sub(r'\r([^\n])', r'\1', output)
|
output = re.sub(r'\r([^\n])', r'\1', output)
|
||||||
|
@ -153,11 +153,11 @@ if sys.version_info[0] == 3:
|
|||||||
if isinstance(value, regex_type):
|
if isinstance(value, regex_type):
|
||||||
if isinstance(value.pattern, bytes):
|
if isinstance(value.pattern, bytes):
|
||||||
return value
|
return value
|
||||||
return re.compile(value.pattern.encode(sys.stdout.encoding),
|
return re.compile(value.pattern.encode(sys.stdout.encoding or 'utf-8'),
|
||||||
value.flags & ~re.UNICODE)
|
value.flags & ~re.UNICODE)
|
||||||
else:
|
else:
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
value = value.encode(sys.stdout.encoding)
|
value = value.encode(sys.stdout.encoding or 'utf-8')
|
||||||
return re.compile(value)
|
return re.compile(value)
|
||||||
else:
|
else:
|
||||||
def regex(value):
|
def regex(value):
|
||||||
|
@ -25,6 +25,6 @@ def get_commit():
|
|||||||
if p.returncode:
|
if p.returncode:
|
||||||
return None
|
return None
|
||||||
if sys.version_info[0] == 3 and isinstance(std, bytes):
|
if sys.version_info[0] == 3 and isinstance(std, bytes):
|
||||||
return std[:8].decode(sys.stdout.encoding, 'replace')
|
return std[:8].decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||||
else:
|
else:
|
||||||
return std[:8]
|
return std[:8]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user