1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-02-25 05:57:51 +00:00

utils.android: Add ApkInfo._run()

Add a _run() method to handle CLI calls from within the class.
This commit is contained in:
Pierre-Clement Tosi 2018-12-18 11:43:44 +00:00 committed by Marc Bonnici
parent 4fabcae0b4
commit 7e0e6e8706

View File

@ -147,15 +147,7 @@ class ApkInfo(object):
# pylint: disable=too-many-branches # pylint: disable=too-many-branches
def parse(self, apk_path): def parse(self, apk_path):
_check_env() _check_env()
command = [aapt, 'dump', 'badging', apk_path] output = self._run([aapt, 'dump', 'badging', apk_path])
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')
except subprocess.CalledProcessError as e:
raise HostError('Error parsing APK file {}. `aapt` says:\n{}'
.format(apk_path, e.output))
for line in output.split('\n'): for line in output.split('\n'):
if line.startswith('application-label:'): if line.startswith('application-label:'):
self.label = line.split(':')[1].strip().replace('\'', '') self.label = line.split(':')[1].strip().replace('\'', '')
@ -188,6 +180,17 @@ class ApkInfo(object):
else: else:
pass # not interested pass # not interested
def _run(self, command):
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')
except subprocess.CalledProcessError as e:
raise HostError('Error while running "{}":\n{}'
.format(command, e.output))
return output
class AdbConnection(object): class AdbConnection(object):