Bug 1008943 - mozinfo should be cheaper to import. r=ahal
authorJulien Pagès <j.parkouss@gmail.com>
Mon, 20 Oct 2014 02:57:00 +0200
changeset 237814 776061abb9be3feedade5a31c84a99f869bbab45
parent 237813 9e996cc695eb5d92e4a7014b19c8e71293ce4b77
child 237815 8c0cf60141dc549a7042b00742761a27e0bedf66
push id660
push userraliiev@mozilla.com
push dateWed, 18 Feb 2015 20:30:48 +0000
treeherdermozilla-release@49e493494178 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1008943
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1008943 - mozinfo should be cheaper to import. r=ahal
testing/mozbase/mozinfo/mozinfo/mozinfo.py
--- a/testing/mozbase/mozinfo/mozinfo/mozinfo.py
+++ b/testing/mozbase/mozinfo/mozinfo/mozinfo.py
@@ -3,26 +3,21 @@
 # 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/.
 
 # TODO: it might be a good idea of adding a system name (e.g. 'Ubuntu' for
 # linux) to the information; I certainly wouldn't want anyone parsing this
 # information and having behaviour depend on it
 
-import ctypes
-import errno
-import json
 import os
 import platform
 import re
 import sys
 
-import mozfile
-
 # keep a copy of the os module since updating globals overrides this
 _os = os
 
 class unknown(object):
     """marker class for unknown information"""
     def __nonzero__(self):
         return False
     def __str__(self):
@@ -92,16 +87,18 @@ elif processor.upper() == "AMD64":
 elif processor == "Power Macintosh":
     processor = "ppc"
 bits = re.search('(\d+)bit', bits).group(1)
 info.update({'processor': processor,
              'bits': int(bits),
             })
 
 if info['os'] == 'linux':
+    import ctypes
+    import errno
     PR_SET_SECCOMP = 22
     SECCOMP_MODE_FILTER = 2
     ctypes.CDLL("libc.so.6", use_errno=True).prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, 0)
     info['has_sandbox'] = ctypes.get_errno() == errno.EFAULT
 else:
     info['has_sandbox'] = True
 
 # standard value of choices, for easy inspection
@@ -127,16 +124,19 @@ 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):
+        # lazy import
+        import mozfile
+        import json
         f = mozfile.load(new_info)
         new_info = json.loads(f.read())
         f.close()
 
     info.update(new_info)
     sanitize(info)
     globals().update(info)
 
@@ -202,16 +202,18 @@ def main(args=None):
     for key in choices:
         parser.add_option('--%s' % key, dest=key,
                           action='store_true', default=False,
                           help="display choices for %s" % key)
     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()
             else:
                 string = arg
             update(json.loads(string))
 
     # print out choices if requested