Bug 1454338 - [mozversion] Remove support for B2G; r?ahal draft
authorDave Hunt <dhunt@mozilla.com>
Mon, 16 Apr 2018 13:16:17 +0100
changeset 782962 c63184d947751e601f5cbe96443d81a3d5fe3fd3
parent 782895 6276ec7ebbf33e3484997b189f20fc1511534187
push id106584
push userbmo:dave.hunt@gmail.com
push dateMon, 16 Apr 2018 13:45:43 +0000
reviewersahal
bugs1454338
milestone61.0a1
Bug 1454338 - [mozversion] Remove support for B2G; r?ahal MozReview-Commit-ID: 9CJ8arQiZtf
testing/mozbase/docs/mozversion.rst
testing/mozbase/mozversion/mozversion/mozversion.py
testing/mozbase/mozversion/setup.py
testing/mozbase/mozversion/tests/manifest.ini
testing/mozbase/mozversion/tests/test_b2g.py
testing/mozbase/mozversion/tests/test_sources.py
--- a/testing/mozbase/docs/mozversion.rst
+++ b/testing/mozbase/docs/mozversion.rst
@@ -1,25 +1,16 @@
 :mod:`mozversion` --- Get application information
 =================================================
 
 `mozversion <https://github.com/mozilla/mozbase/tree/master/mozversion>`_
 provides version information such as the application name and the changesets
 that it has been built from. This is commonly used in reporting or for
 conditional logic based on the application under test.
 
-Note that mozversion can report the version of remote devices (e.g. Firefox OS)
-but it requires the mozdevice dependency in that case. You can require it
-along with mozversion by using the extra *device* dependency:
-
-.. code-block:: bash
-
-  pip install mozversion[device]
-
-
 API Usage
 ---------
 
 .. automodule:: mozversion
     :members: get_version
 
 Examples
 ````````
@@ -33,21 +24,16 @@ Firefox::
         if value:
             print '%s: %s' % (key, value)
 
 Firefox for Android::
 
     version = mozversion.get_version(binary='path/to/firefox.apk')
     print version['application_changeset'] # gets hg revision of build
 
-FirefoxOS::
-
-    version = mozversion.get_version(sources='path/to/sources.xml', dm_type='adb')
-    print version['gaia_changeset'] # gets gaia git revision
-
 Command Line Usage
 ------------------
 
 mozversion comes with a command line program, ``mozversion`` which may be used to
 get version information from an application.
 
 Usage::
 
@@ -59,24 +45,16 @@ Options
 ---binary
 '''''''''
 
 This is the path to the target application binary or .apk. If this is omitted
 then the current directory is checked for the existence of an
 application.ini file. If not found, then it is assumed the target
 application is a remote Firefox OS instance.
 
-
----sources
-''''''''''
-
-The path to the sources.xml that accompanies the target application (Firefox OS
-only). If this is omitted then the current directory is checked for the
-existence of a sources.xml file.
-
 Examples
 ````````
 
 Firefox::
 
     $ mozversion --binary=/path/to/firefox-bin
     application_buildid: 20131205075310
     application_changeset: 39faf812aaec
@@ -85,28 +63,8 @@ Firefox::
     application_version: 26.0
     platform_buildid: 20131205075310
     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
-    application_buildid: 20140106040201
-    application_changeset: 14ac61461f2a
-    application_name: B2G
-    application_repository: http://hg.mozilla.org/mozilla-central
-    application_version: 29.0a1
-    build_changeset: 59605a7c026ff06cc1613af3938579b1dddc6cfe
-    device_firmware_date: 1380051975
-    device_firmware_version_incremental: 139
-    device_firmware_version_release: 4.0.4
-    device_id: msm7627a
-    gaia_changeset: 9a222ac02db176e47299bb37112ae40aeadbeca7
-    gaia_date: 1389005812
-    gecko_changeset: 3a2d8af198510726b063a217438fcf2591f4dfcf
-    platform_buildid: 20140106040201
-    platform_changeset: 14ac61461f2a
-    platform_repository: http://hg.mozilla.org/mozilla-central
--- a/testing/mozbase/mozversion/mozversion/mozversion.py
+++ b/testing/mozbase/mozversion/mozversion/mozversion.py
@@ -1,24 +1,20 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import
 
 import argparse
 import os
-import re
 from six.moves import configparser
 import sys
-import tempfile
-import xml.dom.minidom
 import zipfile
 
-import mozfile
 import mozlog
 
 from mozversion import errors
 
 
 INI_DATA_MAPPING = (('application', 'App'), ('platform', 'Build'))
 
 
@@ -106,133 +102,52 @@ class LocalVersion(Version):
 
         self.get_gecko_info(path)
 
     def check_location(self, path):
         return (os.path.exists(os.path.join(path, 'application.ini'))
                 and os.path.exists(os.path.join(path, 'platform.ini')))
 
 
-class B2GVersion(Version):
-
-    def __init__(self, sources=None, **kwargs):
-        Version.__init__(self, **kwargs)
-
-        sources = sources or \
-            os.path.exists(os.path.join(os.getcwd(), 'sources.xml')) and \
-            os.path.join(os.getcwd(), 'sources.xml')
-
-        if sources and os.path.exists(sources):
-            sources_xml = xml.dom.minidom.parse(sources)
-            for element in sources_xml.getElementsByTagName('project'):
-                path = element.getAttribute('path')
-                changeset = element.getAttribute('revision')
-                if path in ['gaia', 'gecko', 'build']:
-                    if path == 'gaia' and self._info.get('gaia_changeset'):
-                        break
-                    self._info['_'.join([path, 'changeset'])] = changeset
-
-    def get_gaia_info(self, app_zip):
-        tempdir = tempfile.mkdtemp()
-        try:
-            gaia_commit = os.path.join(tempdir, 'gaia_commit.txt')
-            try:
-                zip_file = zipfile.ZipFile(app_zip.name)
-                with open(gaia_commit, 'w') as f:
-                    f.write(zip_file.read('resources/gaia_commit.txt'))
-            except zipfile.BadZipfile:
-                self._logger.info('Unable to unzip application.zip, falling '
-                                  'back to system unzip')
-                from subprocess import call
-                call(['unzip', '-j', app_zip.name, 'resources/gaia_commit.txt',
-                      '-d', tempdir])
-
-            with open(gaia_commit) as f:
-                changeset, date = f.read().splitlines()
-                self._info['gaia_changeset'] = re.match(
-                    '^\w{40}$', changeset) and changeset or None
-                self._info['gaia_date'] = date
-        except KeyError:
-            self._logger.warning(
-                'Unable to find resources/gaia_commit.txt in '
-                'application.zip')
-        finally:
-            mozfile.remove(tempdir)
-
-
-class LocalB2GVersion(B2GVersion):
-
-    def __init__(self, binary, sources=None, **kwargs):
-        B2GVersion.__init__(self, sources, **kwargs)
-
-        if binary:
-            if not os.path.exists(binary):
-                raise IOError('Binary path does not exist: %s' % binary)
-            path = os.path.dirname(binary)
-        else:
-            if os.path.exists(os.path.join(os.getcwd(), 'application.ini')):
-                path = os.getcwd()
-
-        self.get_gecko_info(path)
-
-        zip_path = os.path.join(
-            path, 'gaia', 'profile', 'webapps',
-            'settings.gaiamobile.org', 'application.zip')
-        if os.path.exists(zip_path):
-            with open(zip_path, 'rb') as zip_file:
-                self.get_gaia_info(zip_file)
-        else:
-            self._logger.warning('Error pulling gaia file')
-
-
-def get_version(binary=None, sources=None):
+def get_version(binary=None):
     """
     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 and that the binary path was not specified, then it is
-    assumed the target application is a remote Firefox OS instance.
+    file.
 
     :param binary: Path to the binary for the application or Android APK file
-    :param sources: Path to the sources.xml file (Firefox OS)
     """
     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)
 
     for (key, value) in sorted(version._info.items()):
         if value:
             version._logger.info('%s: %s' % (key, value))
 
     return version._info
 
 
 def cli(args=sys.argv[1:]):
     parser = argparse.ArgumentParser(
         description='Display version information for Mozilla applications')
     parser.add_argument(
         '--binary',
         help='path to application binary or apk')
-    fxos = parser.add_argument_group('Firefox OS')
-    fxos.add_argument(
-        '--sources',
-        help='path to sources.xml')
     mozlog.commandline.add_logging_group(
         parser,
         include_formatters=mozlog.commandline.TEXT_FORMATTERS
     )
 
     args = parser.parse_args()
 
     mozlog.commandline.setup_logging(
         'mozversion', args, {'mach': sys.stdout})
 
-    get_version(binary=args.binary,
-                sources=args.sources)
+    get_version(binary=args.binary)
 
 
 if __name__ == '__main__':
     cli()
--- a/testing/mozbase/mozversion/setup.py
+++ b/testing/mozbase/mozversion/setup.py
@@ -1,34 +1,32 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import
 
 from setuptools import setup
 
-PACKAGE_VERSION = '1.5'
+PACKAGE_VERSION = '2.0.0'
 
 
 setup(name='mozversion',
       version=PACKAGE_VERSION,
       description='Library to get version information for applications',
       long_description="see https://firefox-source-docs.mozilla.org/mozbase/index.html",
       classifiers=['Programming Language :: Python :: 2.7',
                    'Programming Language :: Python :: 3'],
       keywords='mozilla',
       author='Mozilla Automation and Testing Team',
       author_email='tools@lists.mozilla.org',
       url='https://wiki.mozilla.org/Auto-tools/Projects/Mozbase',
       license='MPL',
       packages=['mozversion'],
       include_package_data=True,
       zip_safe=False,
-      install_requires=['mozfile >= 1.0',
-                        'mozlog >= 3.0',
+      install_requires=['mozlog ~= 3.0',
                         'six >= 1.10.0'],
-      extras_require={'device': ['mozdevice >= 0.44']},
       entry_points="""
       # -*- Entry points: -*-
       [console_scripts]
       mozversion = mozversion:cli
       """)
--- a/testing/mozbase/mozversion/tests/manifest.ini
+++ b/testing/mozbase/mozversion/tests/manifest.ini
@@ -1,5 +1,4 @@
 [DEFAULT]
 subsuite = mozbase, os == "linux"
 [test_binary.py]
-[test_sources.py]
 [test_apk.py]
deleted file mode 100644
--- a/testing/mozbase/mozversion/tests/test_b2g.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/env python
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this file,
-# You can obtain one at http://mozilla.org/MPL/2.0/.
-
-from __future__ import absolute_import
-
-import os
-import tempfile
-import unittest
-import zipfile
-
-import mozunit
-
-import mozfile
-from mozversion import get_version
-
-
-class SourcesTest(unittest.TestCase):
-    """test getting version information from a sources xml"""
-
-    def setUp(self):
-        self.tempdir = tempfile.mkdtemp()
-
-        self.binary = os.path.join(self.tempdir, 'binary')
-        with open(self.binary, 'w') as f:
-            f.write('foobar')
-
-        with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
-            f.writelines("""[App]\nName = B2G\n""")
-
-        with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
-            f.write('[Build]\nBuildID = PlatformBuildID\n')
-
-    def tearDown(self):
-        mozfile.remove(self.tempdir)
-
-    def _create_zip(self, revision=None, date=None):
-        zip_path = os.path.join(
-            self.tempdir, 'gaia', 'profile', 'webapps',
-            'settings.gaiamobile.org', 'application.zip')
-        os.makedirs(os.path.dirname(zip_path))
-        app_zip = zipfile.ZipFile(zip_path, 'w')
-        if revision or date:
-            app_zip.writestr('resources/gaia_commit.txt',
-                             '%s\n%s' % (revision, date))
-        app_zip.close()
-
-    def test_gaia_commit(self):
-        revision, date = ('a' * 40, 'date')
-        self._create_zip(revision, date)
-        v = get_version(self.binary)
-        self.assertEqual(v.get('gaia_changeset'), revision)
-        self.assertEqual(v.get('gaia_date'), date)
-
-    def test_invalid_gaia_commit(self):
-        revision, date = ('a' * 41, 'date')
-        self._create_zip(revision, date)
-        v = get_version(self.binary)
-        self.assertIsNone(v.get('gaia_changeset'))
-        self.assertEqual(v.get('gaia_date'), date)
-
-    def test_missing_zip_file(self):
-        v = get_version(self.binary)
-        self.assertIsNone(v.get('gaia_changeset'))
-        self.assertIsNone(v.get('gaia_date'))
-
-    def test_missing_gaia_commit(self):
-        self._create_zip()
-        v = get_version(self.binary)
-        self.assertIsNone(v.get('gaia_changeset'))
-        self.assertIsNone(v.get('gaia_date'))
-
-
-if __name__ == '__main__':
-    mozunit.main()
deleted file mode 100644
--- a/testing/mozbase/mozversion/tests/test_sources.py
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/usr/bin/env python
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this file,
-# You can obtain one at http://mozilla.org/MPL/2.0/.
-
-from __future__ import absolute_import
-
-import os
-import tempfile
-import unittest
-
-import mozunit
-
-import mozfile
-from mozversion import errors, get_version
-
-
-class SourcesTest(unittest.TestCase):
-    """test getting version information from a sources xml"""
-
-    application_ini = """[App]\nName = B2G\n"""
-    platform_ini = """[Build]
-BuildID = PlatformBuildID
-SourceStamp = PlatformSourceStamp
-SourceRepository = PlatformSourceRepo
-"""
-    sources_xml = """<?xml version="1.0" ?><manifest>
-  <project path="build" revision="build_revision" />
-  <project path="gaia" revision="gaia_revision" />
-  <project path="gecko" revision="gecko_revision" />
-</manifest>
-"""
-
-    def setUp(self):
-        self.cwd = os.getcwd()
-        self.tempdir = tempfile.mkdtemp()
-
-        self.binary = os.path.join(self.tempdir, 'binary')
-        with open(self.binary, 'w') as f:
-            f.write('foobar')
-
-    def tearDown(self):
-        os.chdir(self.cwd)
-        mozfile.remove(self.tempdir)
-
-    def _write_conf_files(self, sources=True):
-        with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
-            f.writelines(self.application_ini)
-        with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
-            f.writelines(self.platform_ini)
-        if sources:
-            with open(os.path.join(self.tempdir, 'sources.xml'), 'w') as f:
-                f.writelines(self.sources_xml)
-
-    def test_sources(self):
-        self._write_conf_files()
-
-        os.chdir(self.tempdir)
-        self._check_version(get_version(sources=os.path.join(self.tempdir,
-                                                             'sources.xml')))
-
-    def test_sources_in_current_directory(self):
-        self._write_conf_files()
-
-        os.chdir(self.tempdir)
-        self._check_version(get_version())
-
-    def test_invalid_sources_path(self):
-        """An invalid source path should cause an exception"""
-        self.assertRaises(errors.AppNotFoundError, get_version,
-                          self.binary, os.path.join(self.tempdir, 'invalid'))
-
-    def test_without_sources_file(self):
-        """With a missing sources file no exception should be thrown"""
-        self._write_conf_files(sources=False)
-
-        get_version(self.binary)
-
-    def _check_version(self, version):
-        self.assertEqual(version.get('build_changeset'), 'build_revision')
-        self.assertEqual(version.get('gaia_changeset'), 'gaia_revision')
-        self.assertEqual(version.get('gecko_changeset'), 'gecko_revision')
-        self.assertIsNone(version.get('invalid_key'))
-
-
-if __name__ == '__main__':
-    mozunit.main()