xref: /aosp_15_r20/external/autotest/client/cros/factory_setup_modules.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
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
9import 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).
13sysroot = os.environ.get('SYSROOT')
14extra_path = ([os.path.join(sysroot, 'usr/local/factory/py_pkg')]
15              if sysroot else [])
16
17# Try to import cros, or just create a stub module if it doesn't
18# exist.
19try:
20    import cros
21except:
22    cros = imp.load_module('cros', None, '', ('', '', imp.PKG_DIRECTORY))
23
24# Load cros.factory, inserting it into the cros module.
25cros.factory = imp.load_module(
26    'cros.factory',
27    *imp.find_module('cros/factory', sys.path + extra_path))
28