From 4e494d0b99f9e63506c2716f1bd03ecf0f21c24d Mon Sep 17 00:00:00 2001 From: William Lachance Date: Thu, 29 May 2014 14:57:52 -0400 Subject: [PATCH] Bug 1016467 - Allow mozversion to support getting version info out of a fennec .apk. r=davehunt --- testing/mozbase/docs/mozversion.rst | 12 ++- .../mozversion/mozversion/mozversion.py | 79 ++++++++++++------- testing/mozbase/mozversion/tests/manifest.ini | 1 + 3 files changed, 61 insertions(+), 31 deletions(-) diff --git a/testing/mozbase/docs/mozversion.rst b/testing/mozbase/docs/mozversion.rst index 53c6f98a300c..46669e1a2a01 100644 --- a/testing/mozbase/docs/mozversion.rst +++ b/testing/mozbase/docs/mozversion.rst @@ -29,10 +29,10 @@ Options ---binary ''''''''' -This is the path to the target application binary. If this is omitted then -the current directory is checked for the existance of an application.ini file. -If not found, then it is assumed the target application is a remote Firefox OS -instance. +This is the path to the target application binary or .apk. If this is omitted +then the current directory is checked for the existance of an +application.ini file. If not found, then it is assumed the target +application is a remote Firefox OS instance. ---sources @@ -57,6 +57,10 @@ Firefox:: platform_changeset: 39faf812aaec platform_repository: http://hg.mozilla.org/releases/mozilla-release +Firefox for Android:: + + $ mozversion --binary=/path/to/firefox.apk + Firefox OS:: $ mozversion --sources=/path/to/sources.xml diff --git a/testing/mozbase/mozversion/mozversion/mozversion.py b/testing/mozbase/mozversion/mozversion/mozversion.py index e6d2fff8e755..0f0430b7e2d7 100644 --- a/testing/mozbase/mozversion/mozversion/mozversion.py +++ b/testing/mozbase/mozversion/mozversion/mozversion.py @@ -31,33 +31,52 @@ class LocalAppNotFoundError(VersionError): 'containing the binary.') +INI_DATA_MAPPING = (('application', 'App'), ('platform', 'Build')) + class Version(mozlog.LoggingMixin): def __init__(self): self._info = {} - def get_gecko_info(self, config_path): - for filename, section in (('application', 'App'), - ('platform', 'Build')): - config = ConfigParser.RawConfigParser() - config_file = os.path.join(config_path, '%s.ini' % filename) + def get_gecko_info(self, path): + for type, section in INI_DATA_MAPPING: + config_file = os.path.join(path, "%s.ini" % type) if os.path.exists(config_file): - config.read(config_file) - name_map = {'CodeName': 'display_name', - 'SourceRepository': 'repository', - 'SourceStamp': 'changeset'} - for key in ('BuildID', 'Name', 'CodeName', 'Version', - 'SourceRepository', 'SourceStamp'): - name = name_map.get(key, key).lower() - self._info['%s_%s' % (filename, name)] = config.has_option( - section, key) and config.get(section, key) or None - - if not self._info.get('application_display_name'): - self._info['application_display_name'] = \ - self._info.get('application_name') + self._parse_ini_file(open(config_file), type, section) else: self.warn('Unable to find %s' % config_file) + def _parse_ini_file(self, fp, type, section): + config = ConfigParser.RawConfigParser() + config.readfp(fp) + name_map = {'CodeName': 'display_name', + 'SourceRepository': 'repository', + 'SourceStamp': 'changeset'} + for key in ('BuildID', 'Name', 'CodeName', 'Version', + 'SourceRepository', 'SourceStamp'): + name = name_map.get(key, key).lower() + self._info['%s_%s' % (type, name)] = config.has_option( + section, key) and config.get(section, key) or None + + if not self._info.get('application_display_name'): + self._info['application_display_name'] = \ + self._info.get('application_name') + +class LocalFennecVersion(Version): + + def __init__(self, path, **kwargs): + Version.__init__(self, **kwargs) + self.get_gecko_info(path) + + def get_gecko_info(self, path): + archive = zipfile.ZipFile(path, 'r') + for type, section in INI_DATA_MAPPING: + filename = "%s.ini" % type + if filename in archive.namelist(): + self._parse_ini_file(archive.open(filename), type, + section) + else: + self.warn('Unable to find %s' % filename) class LocalVersion(Version): @@ -201,20 +220,26 @@ class RemoteB2GVersion(B2GVersion): def get_version(binary=None, sources=None, dm_type=None, host=None): """ - Returns the application version information as a dict. If binary path is - omitted then the current directory is checked for the existance of an - application.ini file. If not found, then it is assumed the target - application is a remote Firefox OS instance. + Returns the application version information as a dict. You can specify + a path to the binary of the application or an Android APK file (to get + version information for Firefox for Android). If this is omitted then the + current directory is checked for the existance of an application.ini + file. If not found, then it is assumed the target application is a remote + Firefox OS instance. - :param binary: Path to the binary for the application + :param binary: Path to the binary for the application or Android APK file :param sources: Path to the sources.xml file (Firefox OS) :param dm_type: Device manager type. Must be 'adb' or 'sut' (Firefox OS) :param host: Host address of remote Firefox OS instance (SUT) """ try: - version = LocalVersion(binary) - if version._info.get('application_name') == 'B2G': - version = LocalB2GVersion(binary, sources=sources) + if binary and zipfile.is_zipfile(binary) and 'AndroidManifest.xml' in \ + zipfile.ZipFile(binary, 'r').namelist(): + version = LocalFennecVersion(binary) + else: + version = LocalVersion(binary) + if version._info.get('application_name') == 'B2G': + version = LocalB2GVersion(binary, sources=sources) except LocalAppNotFoundError: version = RemoteB2GVersion(sources=sources, dm_type=dm_type, host=host) return version._info @@ -224,7 +249,7 @@ def cli(args=sys.argv[1:]): parser = OptionParser() parser.add_option('--binary', dest='binary', - help='path to application binary') + help='path to application binary or apk') parser.add_option('--sources', dest='sources', help='path to sources.xml (Firefox OS only)') diff --git a/testing/mozbase/mozversion/tests/manifest.ini b/testing/mozbase/mozversion/tests/manifest.ini index cf46e03d59f8..3c034ea785da 100644 --- a/testing/mozbase/mozversion/tests/manifest.ini +++ b/testing/mozbase/mozversion/tests/manifest.ini @@ -1,3 +1,4 @@ [test_binary.py] [test_sources.py] [test_b2g.py] +[test_apk.py] \ No newline at end of file