mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
devlib: Remove Python 2 dead code
Remove code that was used for Python 2 only.
This commit is contained in:
parent
ea4eccf95d
commit
416e8ac40f
@ -408,8 +408,7 @@ class FtraceCollector(CollectorBase):
|
||||
self.logger.debug(command)
|
||||
process = subprocess.Popen(command, stderr=subprocess.PIPE, shell=True)
|
||||
_, error = process.communicate()
|
||||
if sys.version_info[0] == 3:
|
||||
error = error.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
error = error.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
if process.returncode:
|
||||
raise TargetStableError('trace-cmd returned non-zero exit code {}'.format(process.returncode))
|
||||
if error:
|
||||
|
@ -116,10 +116,7 @@ class AcmeCapeInstrument(Instrument):
|
||||
msg = 'Could not terminate iio-capture:\n{}'
|
||||
raise HostError(msg.format(output))
|
||||
if self.process.returncode != 15: # iio-capture exits with 15 when killed
|
||||
if sys.version_info[0] == 3:
|
||||
output += self.process.stdout.read().decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
else:
|
||||
output += self.process.stdout.read()
|
||||
output += self.process.stdout.read().decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
self.logger.info('ACME instrument encountered an error, '
|
||||
'you may want to try rebooting the ACME device:\n'
|
||||
' ssh root@{} reboot'.format(self.host))
|
||||
|
@ -86,9 +86,8 @@ class EnergyProbeInstrument(Instrument):
|
||||
self.process.poll()
|
||||
if self.process.returncode is not None:
|
||||
stdout, stderr = self.process.communicate()
|
||||
if sys.version_info[0] == 3:
|
||||
stdout = stdout.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
stderr = stderr.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
stdout = stdout.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
stderr = stderr.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
raise HostError(
|
||||
'Energy Probe: Caiman exited unexpectedly with exit code {}.\n'
|
||||
'stdout:\n{}\nstderr:\n{}'.format(self.process.returncode,
|
||||
|
@ -100,9 +100,8 @@ class MonsoonInstrument(Instrument):
|
||||
process.poll()
|
||||
if process.returncode is not None:
|
||||
stdout, stderr = process.communicate()
|
||||
if sys.version_info[0] == 3:
|
||||
stdout = stdout.encode(sys.stdout.encoding or 'utf-8')
|
||||
stderr = stderr.encode(sys.stdout.encoding or 'utf-8')
|
||||
stdout = stdout.encode(sys.stdout.encoding or 'utf-8')
|
||||
stderr = stderr.encode(sys.stdout.encoding or 'utf-8')
|
||||
raise HostError(
|
||||
'Monsoon script exited unexpectedly with exit code {}.\n'
|
||||
'stdout:\n{}\nstderr:\n{}'.format(process.returncode,
|
||||
|
@ -2029,10 +2029,7 @@ class AndroidTarget(Target):
|
||||
|
||||
parsed_xml = xml.dom.minidom.parse(filepath)
|
||||
with open(filepath, 'w') as f:
|
||||
if sys.version_info[0] == 3:
|
||||
f.write(parsed_xml.toprettyxml())
|
||||
else:
|
||||
f.write(parsed_xml.toprettyxml().encode('utf-8'))
|
||||
f.write(parsed_xml.toprettyxml())
|
||||
|
||||
@asyn.asyncf
|
||||
async def is_installed(self, name):
|
||||
|
@ -246,8 +246,7 @@ class ApkInfo(object):
|
||||
logger.debug(' '.join(command))
|
||||
try:
|
||||
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
|
||||
if sys.version_info[0] == 3:
|
||||
output = output.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
output = output.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise HostError('Error while running "{}":\n{}'
|
||||
.format(command, e.output))
|
||||
|
@ -60,10 +60,7 @@ from contextlib import contextmanager
|
||||
|
||||
@contextmanager
|
||||
def csvwriter(filepath, *args, **kwargs):
|
||||
if sys.version_info[0] == 3:
|
||||
wfh = open(filepath, 'w', newline='')
|
||||
else:
|
||||
wfh = open(filepath, 'wb')
|
||||
wfh = open(filepath, 'w', newline='')
|
||||
|
||||
try:
|
||||
yield csv.writer(wfh, *args, **kwargs)
|
||||
@ -73,10 +70,7 @@ def csvwriter(filepath, *args, **kwargs):
|
||||
|
||||
@contextmanager
|
||||
def csvreader(filepath, *args, **kwargs):
|
||||
if sys.version_info[0] == 3:
|
||||
fh = open(filepath, 'r', newline='')
|
||||
else:
|
||||
fh = open(filepath, 'rb')
|
||||
fh = open(filepath, 'r', newline='')
|
||||
|
||||
try:
|
||||
yield csv.reader(fh, *args, **kwargs)
|
||||
@ -85,16 +79,10 @@ def csvreader(filepath, *args, **kwargs):
|
||||
|
||||
|
||||
def create_writer(filepath, *args, **kwargs):
|
||||
if sys.version_info[0] == 3:
|
||||
wfh = open(filepath, 'w', newline='')
|
||||
else:
|
||||
wfh = open(filepath, 'wb')
|
||||
wfh = open(filepath, 'w', newline='')
|
||||
return csv.writer(wfh, *args, **kwargs), wfh
|
||||
|
||||
|
||||
def create_reader(filepath, *args, **kwargs):
|
||||
if sys.version_info[0] == 3:
|
||||
fh = open(filepath, 'r', newline='')
|
||||
else:
|
||||
fh = open(filepath, 'rb')
|
||||
fh = open(filepath, 'r', newline='')
|
||||
return csv.reader(fh, *args, **kwargs), fh
|
||||
|
@ -594,11 +594,7 @@ class LoadSyntaxError(Exception):
|
||||
|
||||
RAND_MOD_NAME_LEN = 30
|
||||
BAD_CHARS = string.punctuation + string.whitespace
|
||||
# pylint: disable=no-member
|
||||
if sys.version_info[0] == 3:
|
||||
TRANS_TABLE = str.maketrans(BAD_CHARS, '_' * len(BAD_CHARS))
|
||||
else:
|
||||
TRANS_TABLE = string.maketrans(BAD_CHARS, '_' * len(BAD_CHARS))
|
||||
TRANS_TABLE = str.maketrans(BAD_CHARS, '_' * len(BAD_CHARS))
|
||||
|
||||
|
||||
def to_identifier(text):
|
||||
|
@ -217,10 +217,7 @@ class GfxinfoFrameCollector(FrameCollector):
|
||||
def collect_frames(self, wfh):
|
||||
cmd = 'dumpsys gfxinfo {} framestats'
|
||||
result = self.target.execute(cmd.format(self.package))
|
||||
if sys.version_info[0] == 3:
|
||||
wfh.write(result.encode('utf-8'))
|
||||
else:
|
||||
wfh.write(result)
|
||||
wfh.write(result.encode('utf-8'))
|
||||
|
||||
def clear(self):
|
||||
pass
|
||||
|
@ -758,11 +758,7 @@ class SshConnection(SshConnectionBase):
|
||||
output_chunks, exit_code = _read_paramiko_streams(stdout, stderr, select_timeout, callback, [])
|
||||
# Join in one go to avoid O(N^2) concatenation
|
||||
output = b''.join(output_chunks)
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
output = output.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
if strip_colors:
|
||||
output = strip_bash_colors(output)
|
||||
output = output.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
|
||||
return (exit_code, output)
|
||||
|
||||
@ -970,10 +966,7 @@ class TelnetConnection(SshConnectionBase):
|
||||
logger.debug(command)
|
||||
self._sendline(command)
|
||||
timed_out = self._wait_for_prompt(timeout)
|
||||
if sys.version_info[0] == 3:
|
||||
output = process_backspaces(self.conn.before.decode(sys.stdout.encoding or 'utf-8', 'replace'))
|
||||
else:
|
||||
output = process_backspaces(self.conn.before)
|
||||
output = process_backspaces(self.conn.before.decode(sys.stdout.encoding or 'utf-8', 'replace'))
|
||||
|
||||
if timed_out:
|
||||
self.cancel_running_command()
|
||||
|
@ -136,35 +136,25 @@ def bitmask(value):
|
||||
regex_type = type(re.compile(''))
|
||||
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
def regex(value):
|
||||
if isinstance(value, regex_type):
|
||||
if isinstance(value.pattern, str):
|
||||
return value
|
||||
return re.compile(value.pattern.decode(),
|
||||
value.flags | re.UNICODE)
|
||||
else:
|
||||
if isinstance(value, bytes):
|
||||
value = value.decode()
|
||||
return re.compile(value)
|
||||
|
||||
|
||||
def bytes_regex(value):
|
||||
if isinstance(value, regex_type):
|
||||
if isinstance(value.pattern, bytes):
|
||||
return value
|
||||
return re.compile(value.pattern.encode(sys.stdout.encoding or 'utf-8'),
|
||||
value.flags & ~re.UNICODE)
|
||||
else:
|
||||
if isinstance(value, str):
|
||||
value = value.encode(sys.stdout.encoding or 'utf-8')
|
||||
return re.compile(value)
|
||||
else:
|
||||
def regex(value):
|
||||
if isinstance(value, regex_type):
|
||||
def regex(value):
|
||||
if isinstance(value, regex_type):
|
||||
if isinstance(value.pattern, str):
|
||||
return value
|
||||
else:
|
||||
return re.compile(value)
|
||||
return re.compile(value.pattern.decode(),
|
||||
value.flags | re.UNICODE)
|
||||
else:
|
||||
if isinstance(value, bytes):
|
||||
value = value.decode()
|
||||
return re.compile(value)
|
||||
|
||||
|
||||
bytes_regex = regex
|
||||
def bytes_regex(value):
|
||||
if isinstance(value, regex_type):
|
||||
if isinstance(value.pattern, bytes):
|
||||
return value
|
||||
return re.compile(value.pattern.encode(sys.stdout.encoding or 'utf-8'),
|
||||
value.flags & ~re.UNICODE)
|
||||
else:
|
||||
if isinstance(value, str):
|
||||
value = value.encode(sys.stdout.encoding or 'utf-8')
|
||||
return re.compile(value)
|
||||
|
@ -42,7 +42,7 @@ def get_commit():
|
||||
p.wait()
|
||||
if p.returncode:
|
||||
return None
|
||||
if sys.version_info[0] == 3 and isinstance(std, bytes):
|
||||
if isinstance(std, bytes):
|
||||
return std[:8].decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||
else:
|
||||
return std[:8]
|
||||
|
Loading…
x
Reference in New Issue
Block a user