environment_factory.py (1615B)
1 # Copyright 2014 The Chromium Authors 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 from pylib import constants 6 from pylib.local.device import local_device_environment 7 from pylib.local.device import local_device_network_environment 8 from pylib.local.machine import local_machine_environment 9 10 try: 11 # local_emulator_environment depends on //tools. 12 # If a client pulls in the //build subtree but not the //tools 13 # one, fail at emulator environment creation time. 14 from pylib.local.emulator import local_emulator_environment 15 except ImportError: 16 local_emulator_environment = None 17 18 19 def CreateEnvironment(args, output_manager, error_func): 20 21 if args.environment == 'local': 22 if args.command not in constants.LOCAL_MACHINE_TESTS: 23 if args.avd_config: 24 if not local_emulator_environment: 25 error_func('emulator environment requested but not available.') 26 raise RuntimeError('error_func must call exit inside.') 27 return local_emulator_environment.LocalEmulatorEnvironment( 28 args, output_manager, error_func) 29 30 if args.connect_over_network: 31 return local_device_network_environment.LocalDeviceNetworkEnvironment( 32 args, output_manager, error_func) 33 34 return local_device_environment.LocalDeviceEnvironment( 35 args, output_manager, error_func) 36 return local_machine_environment.LocalMachineEnvironment( 37 args, output_manager, error_func) 38 39 error_func('Unable to create %s environment.' % args.environment) 40 raise RuntimeError('error_func must call exit inside.')