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,7 +408,6 @@ class FtraceCollector(CollectorBase):
|
|||||||
self.logger.debug(command)
|
self.logger.debug(command)
|
||||||
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:
|
|
||||||
error = error.decode(sys.stdout.encoding or 'utf-8', '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))
|
||||||
|
@ -116,10 +116,7 @@ class AcmeCapeInstrument(Instrument):
|
|||||||
msg = 'Could not terminate iio-capture:\n{}'
|
msg = 'Could not terminate iio-capture:\n{}'
|
||||||
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:
|
|
||||||
output += self.process.stdout.read().decode(sys.stdout.encoding or 'utf-8', 'replace')
|
output += self.process.stdout.read().decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||||
else:
|
|
||||||
output += self.process.stdout.read()
|
|
||||||
self.logger.info('ACME instrument encountered an error, '
|
self.logger.info('ACME instrument encountered an error, '
|
||||||
'you may want to try rebooting the ACME device:\n'
|
'you may want to try rebooting the ACME device:\n'
|
||||||
' ssh root@{} reboot'.format(self.host))
|
' ssh root@{} reboot'.format(self.host))
|
||||||
|
@ -86,7 +86,6 @@ class EnergyProbeInstrument(Instrument):
|
|||||||
self.process.poll()
|
self.process.poll()
|
||||||
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:
|
|
||||||
stdout = stdout.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')
|
stderr = stderr.decode(sys.stdout.encoding or 'utf-8', 'replace')
|
||||||
raise HostError(
|
raise HostError(
|
||||||
|
@ -100,7 +100,6 @@ class MonsoonInstrument(Instrument):
|
|||||||
process.poll()
|
process.poll()
|
||||||
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:
|
|
||||||
stdout = stdout.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')
|
stderr = stderr.encode(sys.stdout.encoding or 'utf-8')
|
||||||
raise HostError(
|
raise HostError(
|
||||||
|
@ -2029,10 +2029,7 @@ class AndroidTarget(Target):
|
|||||||
|
|
||||||
parsed_xml = xml.dom.minidom.parse(filepath)
|
parsed_xml = xml.dom.minidom.parse(filepath)
|
||||||
with open(filepath, 'w') as f:
|
with open(filepath, 'w') as f:
|
||||||
if sys.version_info[0] == 3:
|
|
||||||
f.write(parsed_xml.toprettyxml())
|
f.write(parsed_xml.toprettyxml())
|
||||||
else:
|
|
||||||
f.write(parsed_xml.toprettyxml().encode('utf-8'))
|
|
||||||
|
|
||||||
@asyn.asyncf
|
@asyn.asyncf
|
||||||
async def is_installed(self, name):
|
async def is_installed(self, name):
|
||||||
|
@ -246,7 +246,6 @@ class ApkInfo(object):
|
|||||||
logger.debug(' '.join(command))
|
logger.debug(' '.join(command))
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
|
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:
|
except subprocess.CalledProcessError as e:
|
||||||
raise HostError('Error while running "{}":\n{}'
|
raise HostError('Error while running "{}":\n{}'
|
||||||
|
@ -60,10 +60,7 @@ from contextlib import contextmanager
|
|||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def csvwriter(filepath, *args, **kwargs):
|
def csvwriter(filepath, *args, **kwargs):
|
||||||
if sys.version_info[0] == 3:
|
|
||||||
wfh = open(filepath, 'w', newline='')
|
wfh = open(filepath, 'w', newline='')
|
||||||
else:
|
|
||||||
wfh = open(filepath, 'wb')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield csv.writer(wfh, *args, **kwargs)
|
yield csv.writer(wfh, *args, **kwargs)
|
||||||
@ -73,10 +70,7 @@ def csvwriter(filepath, *args, **kwargs):
|
|||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def csvreader(filepath, *args, **kwargs):
|
def csvreader(filepath, *args, **kwargs):
|
||||||
if sys.version_info[0] == 3:
|
|
||||||
fh = open(filepath, 'r', newline='')
|
fh = open(filepath, 'r', newline='')
|
||||||
else:
|
|
||||||
fh = open(filepath, 'rb')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield csv.reader(fh, *args, **kwargs)
|
yield csv.reader(fh, *args, **kwargs)
|
||||||
@ -85,16 +79,10 @@ def csvreader(filepath, *args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def create_writer(filepath, *args, **kwargs):
|
def create_writer(filepath, *args, **kwargs):
|
||||||
if sys.version_info[0] == 3:
|
|
||||||
wfh = open(filepath, 'w', newline='')
|
wfh = open(filepath, 'w', newline='')
|
||||||
else:
|
|
||||||
wfh = open(filepath, 'wb')
|
|
||||||
return csv.writer(wfh, *args, **kwargs), wfh
|
return csv.writer(wfh, *args, **kwargs), wfh
|
||||||
|
|
||||||
|
|
||||||
def create_reader(filepath, *args, **kwargs):
|
def create_reader(filepath, *args, **kwargs):
|
||||||
if sys.version_info[0] == 3:
|
|
||||||
fh = open(filepath, 'r', newline='')
|
fh = open(filepath, 'r', newline='')
|
||||||
else:
|
|
||||||
fh = open(filepath, 'rb')
|
|
||||||
return csv.reader(fh, *args, **kwargs), fh
|
return csv.reader(fh, *args, **kwargs), fh
|
||||||
|
@ -594,11 +594,7 @@ class LoadSyntaxError(Exception):
|
|||||||
|
|
||||||
RAND_MOD_NAME_LEN = 30
|
RAND_MOD_NAME_LEN = 30
|
||||||
BAD_CHARS = string.punctuation + string.whitespace
|
BAD_CHARS = string.punctuation + string.whitespace
|
||||||
# pylint: disable=no-member
|
TRANS_TABLE = str.maketrans(BAD_CHARS, '_' * len(BAD_CHARS))
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
def to_identifier(text):
|
def to_identifier(text):
|
||||||
|
@ -217,10 +217,7 @@ class GfxinfoFrameCollector(FrameCollector):
|
|||||||
def collect_frames(self, wfh):
|
def collect_frames(self, wfh):
|
||||||
cmd = 'dumpsys gfxinfo {} framestats'
|
cmd = 'dumpsys gfxinfo {} framestats'
|
||||||
result = self.target.execute(cmd.format(self.package))
|
result = self.target.execute(cmd.format(self.package))
|
||||||
if sys.version_info[0] == 3:
|
|
||||||
wfh.write(result.encode('utf-8'))
|
wfh.write(result.encode('utf-8'))
|
||||||
else:
|
|
||||||
wfh.write(result)
|
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
pass
|
pass
|
||||||
|
@ -758,11 +758,7 @@ class SshConnection(SshConnectionBase):
|
|||||||
output_chunks, exit_code = _read_paramiko_streams(stdout, stderr, select_timeout, callback, [])
|
output_chunks, exit_code = _read_paramiko_streams(stdout, stderr, select_timeout, callback, [])
|
||||||
# Join in one go to avoid O(N^2) concatenation
|
# Join in one go to avoid O(N^2) concatenation
|
||||||
output = b''.join(output_chunks)
|
output = b''.join(output_chunks)
|
||||||
|
|
||||||
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')
|
||||||
if strip_colors:
|
|
||||||
output = strip_bash_colors(output)
|
|
||||||
|
|
||||||
return (exit_code, output)
|
return (exit_code, output)
|
||||||
|
|
||||||
@ -970,10 +966,7 @@ class TelnetConnection(SshConnectionBase):
|
|||||||
logger.debug(command)
|
logger.debug(command)
|
||||||
self._sendline(command)
|
self._sendline(command)
|
||||||
timed_out = self._wait_for_prompt(timeout)
|
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'))
|
output = process_backspaces(self.conn.before.decode(sys.stdout.encoding or 'utf-8', 'replace'))
|
||||||
else:
|
|
||||||
output = process_backspaces(self.conn.before)
|
|
||||||
|
|
||||||
if timed_out:
|
if timed_out:
|
||||||
self.cancel_running_command()
|
self.cancel_running_command()
|
||||||
|
@ -136,8 +136,7 @@ def bitmask(value):
|
|||||||
regex_type = type(re.compile(''))
|
regex_type = type(re.compile(''))
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[0] == 3:
|
def regex(value):
|
||||||
def regex(value):
|
|
||||||
if isinstance(value, regex_type):
|
if isinstance(value, regex_type):
|
||||||
if isinstance(value.pattern, str):
|
if isinstance(value.pattern, str):
|
||||||
return value
|
return value
|
||||||
@ -149,7 +148,7 @@ if sys.version_info[0] == 3:
|
|||||||
return re.compile(value)
|
return re.compile(value)
|
||||||
|
|
||||||
|
|
||||||
def bytes_regex(value):
|
def bytes_regex(value):
|
||||||
if isinstance(value, regex_type):
|
if isinstance(value, regex_type):
|
||||||
if isinstance(value.pattern, bytes):
|
if isinstance(value.pattern, bytes):
|
||||||
return value
|
return value
|
||||||
@ -159,12 +158,3 @@ if sys.version_info[0] == 3:
|
|||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
value = value.encode(sys.stdout.encoding or 'utf-8')
|
value = value.encode(sys.stdout.encoding or 'utf-8')
|
||||||
return re.compile(value)
|
return re.compile(value)
|
||||||
else:
|
|
||||||
def regex(value):
|
|
||||||
if isinstance(value, regex_type):
|
|
||||||
return value
|
|
||||||
else:
|
|
||||||
return re.compile(value)
|
|
||||||
|
|
||||||
|
|
||||||
bytes_regex = regex
|
|
||||||
|
@ -42,7 +42,7 @@ def get_commit():
|
|||||||
p.wait()
|
p.wait()
|
||||||
if p.returncode:
|
if p.returncode:
|
||||||
return None
|
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')
|
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