Home | History | Annotate | Download | only in cros
      1 # Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 # Sets up the cros.factory module path.  This is necessary since there
      6 # is already a cros directory, and we need to rejigger things so that
      7 # cros.factory points to the correct path.
      8 
      9 import imp, logging, os, sys
     10 
     11 # If SYSROOT is present, also look in
     12 # $SYSROOT/usr/local/factory/py_pkg (necessary during the build step).
     13 sysroot = os.environ.get('SYSROOT')
     14 extra_path = ([os.path.join(sysroot, 'usr/local/factory/py_pkg')]
     15               if sysroot else [])
     16 
     17 # Try to import cros, or just create a dummy module if it doesn't
     18 # exist.
     19 try:
     20     import cros
     21 except:
     22     cros = imp.load_module('cros', None, '', ('', '', imp.PKG_DIRECTORY))
     23 
     24 # Load cros.factory, inserting it into the cros module.
     25 cros.factory = imp.load_module(
     26     'cros.factory',
     27     *imp.find_module('cros/factory', sys.path + extra_path))
     28