mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-18 03:56:04 +00:00
Fixed dev_scripts/get_apk_versions.
It was relying on a distmanagement module that no longer exists. The required functionality from that module is now part of the script.
This commit is contained in:
parent
aa74e1e8f5
commit
cce287a1e7
@ -1,13 +1,82 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import logging
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from wlauto.exceptions import WAError
|
||||
from wlauto.utils.misc import write_table
|
||||
from distmanagement.apk import get_aapt_path, get_apk_versions
|
||||
from wlauto.exceptions import WAError, ToolError
|
||||
from wlauto.utils.doc import format_simple_table
|
||||
|
||||
|
||||
def get_aapt_path():
|
||||
"""Return the full path to aapt tool."""
|
||||
sdk_path = os.getenv('ANDROID_HOME')
|
||||
if not sdk_path:
|
||||
raise ToolError('Please make sure you have Android SDK installed and have ANDROID_HOME set.')
|
||||
build_tools_directory = os.path.join(sdk_path, 'build-tools')
|
||||
versions = os.listdir(build_tools_directory)
|
||||
for version in reversed(sorted(versions)):
|
||||
aapt_path = os.path.join(build_tools_directory, version, 'aapt')
|
||||
if os.path.isfile(aapt_path):
|
||||
logging.debug('Found aapt for version {}'.format(version))
|
||||
return aapt_path
|
||||
else:
|
||||
raise ToolError('aapt not found. Please make sure at least one Android platform is installed.')
|
||||
|
||||
|
||||
def get_apks(path):
|
||||
"""Return a list of paths to all APK files found under the specified directory."""
|
||||
apks = []
|
||||
for root, dirs, files in os.walk(path):
|
||||
for file in files:
|
||||
_, ext = os.path.splitext(file)
|
||||
if ext.lower() == '.apk':
|
||||
apks.append(os.path.join(root, file))
|
||||
return apks
|
||||
|
||||
|
||||
class ApkVersionInfo(object):
|
||||
|
||||
def __init__(self, workload=None, package=None, label=None, version_name=None, version_code=None):
|
||||
self.workload = workload
|
||||
self.package = package
|
||||
self.label = label
|
||||
self.version_name = version_name
|
||||
self.version_code = version_code
|
||||
|
||||
def to_tuple(self):
|
||||
return (self.workload, self.package, self.label, self.version_name, self.version_code)
|
||||
|
||||
|
||||
version_regex = re.compile(r"name='(?P<name>[^']+)' versionCode='(?P<vcode>[^']+)' versionName='(?P<vname>[^']+)'")
|
||||
|
||||
|
||||
def extract_version_info(apk_path, aapt):
|
||||
command = [aapt, 'dump', 'badging', apk_path]
|
||||
output = subprocess.check_output(command)
|
||||
version_info = ApkVersionInfo(workload=apk_path.split(os.sep)[-2])
|
||||
for line in output.split('\n'):
|
||||
if line.startswith('application-label:'):
|
||||
version_info.label = line.split(':')[1].strip().replace('\'', '')
|
||||
elif line.startswith('package:'):
|
||||
match = version_regex.search(line)
|
||||
if match:
|
||||
version_info.package = match.group('name')
|
||||
version_info.version_code = match.group('vcode')
|
||||
version_info.version_name = match.group('vname')
|
||||
else:
|
||||
pass # not interested
|
||||
return version_info
|
||||
|
||||
|
||||
def get_apk_versions(path, aapt):
|
||||
apks = get_apks(path)
|
||||
versions = [extract_version_info(apk, aapt) for apk in apks]
|
||||
return versions
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@ -18,8 +87,10 @@ if __name__ == '__main__':
|
||||
args = parser.parse_args()
|
||||
|
||||
versions = get_apk_versions(args.path, aapt)
|
||||
write_table([v.to_tuple() for v in versions], sys.stdout,
|
||||
align='<<<>>', headers=['path', 'package', 'name', 'version code', 'version name'])
|
||||
table = format_simple_table([v.to_tuple() for v in versions],
|
||||
align='<<<>>',
|
||||
headers=['workload', 'package', 'name', 'version code', 'version name'])
|
||||
print table
|
||||
except WAError, e:
|
||||
logging.error(e)
|
||||
sys.exit(1)
|
||||
|
Loading…
Reference in New Issue
Block a user