Bug 1426330 - Add python 3 support for mozinfo. r=wlach draft
authorVedant Chakravadhanula <vedantc98@gmail.com>
Wed, 27 Dec 2017 12:51:10 +0530
changeset 714617 1b77e80c473dbbc79cd987b2a01f84d08c539135
parent 712870 7c4579e705c4a3a3610183fe6f44affff3ad57ef
child 744632 b01903b25b2d5d5085451dd4c572dd3f3be20cdf
push id93973
push userbmo:vedantc98@gmail.com
push dateWed, 27 Dec 2017 07:22:45 +0000
reviewerswlach
bugs1426330
milestone59.0a1
Bug 1426330 - Add python 3 support for mozinfo. r=wlach MozReview-Commit-ID: CRoF4mk9ASA
testing/mozbase/mozinfo/mozinfo/mozinfo.py
testing/mozbase/mozinfo/setup.py
--- a/testing/mozbase/mozinfo/mozinfo/mozinfo.py
+++ b/testing/mozbase/mozinfo/mozinfo/mozinfo.py
@@ -11,16 +11,17 @@
 from __future__ import absolute_import, print_function
 
 import os
 import platform
 import re
 import sys
 from .string_version import StringVersion
 from ctypes.util import find_library
+from six import string_types
 
 # keep a copy of the os module since updating globals overrides this
 _os = os
 
 
 class unknown(object):
     """marker class for unknown information"""
 
@@ -183,17 +184,17 @@ def sanitize(info):
 def update(new_info):
     """
     Update the info.
 
     :param new_info: Either a dict containing the new info or a path/url
                      to a json file containing the new info.
     """
 
-    if isinstance(new_info, basestring):
+    if isinstance(new_info, string_types):
         # lazy import
         import mozfile
         import json
         f = mozfile.load(new_info)
         new_info = json.loads(f.read())
         f.close()
 
     info.update(new_info)
@@ -247,17 +248,17 @@ def output_to_file(path):
     import json
     with open(path, 'w') as f:
         f.write(json.dumps(info))
 
 
 update({})
 
 # exports
-__all__ = info.keys()
+__all__ = list(info.keys())
 __all__ += ['is' + os_name.title() for os_name in choices['os']]
 __all__ += [
     'info',
     'unknown',
     'main',
     'choices',
     'update',
     'find_and_update_from_json',
@@ -278,17 +279,17 @@ def main(args=None):
     options, args = parser.parse_args()
 
     # args are JSON blobs to override info
     if args:
         # lazy import
         import json
         for arg in args:
             if _os.path.exists(arg):
-                string = file(arg).read()
+                string = open(arg).read()
             else:
                 string = arg
             update(json.loads(string))
 
     # print out choices if requested
     flag = False
     for key, value in options.__dict__.items():
         if value is True:
--- a/testing/mozbase/mozinfo/setup.py
+++ b/testing/mozbase/mozinfo/setup.py
@@ -4,24 +4,25 @@
 
 from __future__ import absolute_import
 
 from setuptools import setup
 
 PACKAGE_VERSION = '0.10'
 
 # dependencies
-deps = ['mozfile >= 0.12']
+deps = ['mozfile >= 0.12',
+        'six >= 1.10.0']
 
 setup(name='mozinfo',
       version=PACKAGE_VERSION,
       description="Library to get system information for use in Mozilla testing",
       long_description="see https://firefox-source-docs.mozilla.org/mozbase/index.html",
       classifiers=['Programming Language :: Python :: 2.7',
-                   'Programming Language :: Python :: 2 :: Only'],
+                   'Programming Language :: Python :: 3'],
       # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
       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=['mozinfo'],
       include_package_data=True,