Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 The Chromium 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 import logging | |
| 6 import os | |
| 7 import sys | |
| 8 import threading | |
| 9 | |
| 10 # TODO(jbudorick): Update this once dependency_manager moves to catapult. | |
| 11 _TELEMETRY_PATH = os.path.abspath(os.path.join( | |
| 12 os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, | |
| 13 'tools', 'telemetry')) | |
| 14 sys.path.append(_TELEMETRY_PATH) | |
| 15 from catapult_base import dependency_manager # pylint: disable=import-error | |
| 16 | |
| 17 | |
| 18 instance = None | |
| 19 | |
| 20 | |
| 21 class _Environment(object): | |
| 22 | |
| 23 def __init__(self, config_files): | |
|
perezju
2015/09/14 09:13:58
Suggestion, make it something like:
class _Enviro
jbudorick
2015/09/14 13:12:39
Hm, this is an interesting idea. I'll try it & get
| |
| 24 dm = dependency_manager.DependencyManager( | |
| 25 [dependency_manager.BaseConfig(c) for c in config_files]) | |
| 26 platform = 'linux_android' | |
| 27 | |
| 28 self._android_sdk_path = dm.FetchPath('android_sdk', platform) | |
| 29 self._adb_path = ( | |
| 30 dm.FetchPath('adb_path', platform) | |
| 31 or os.path.join(self._android_sdk_path, 'platform-tools', 'adb')) | |
| 32 | |
| 33 build_tools_contents = os.listdir( | |
| 34 os.path.join(self._android_sdk_path, 'build-tools')) | |
| 35 if not build_tools_contents: | |
| 36 self._android_sdk_build_tools_path = None | |
| 37 else: | |
| 38 if len(build_tools_contents) > 1: | |
| 39 build_tools_contents.sort() | |
|
perezju
2015/09/14 09:13:58
if there are multiple build_tools, how do they typ
jbudorick
2015/09/14 13:12:39
I've never seen multiple, but they're typically na
| |
| 40 logging.warning( | |
| 41 'More than one set of build-tools provided by the Android SDK: %s', | |
| 42 ','.join(build_tools_contents)) | |
| 43 logging.warning('Defaulting to %s', build_tools_contents[-1]) | |
| 44 self._android_sdk_build_tools_path = os.path.join( | |
| 45 self._android_sdk_path, 'build-tools', build_tools_contents[-1]) | |
| 46 | |
| 47 self._forwarder_host_path = dm.FetchPath('forwarder_host', platform) | |
| 48 self._forwarder_device_path = dm.FetchPath('forwarder_device', platform) | |
| 49 | |
| 50 self._md5sum_host_path = dm.FetchPath('md5sum_host', platform) | |
| 51 self._md5sum_device_path = dm.FetchPath('md5sum_device', platform) | |
| 52 | |
| 53 self._pymock_path = dm.FetchPath('pymock', platform) | |
| 54 | |
| 55 @property | |
| 56 def adb_path(self): | |
| 57 return self._adb_path | |
| 58 | |
| 59 @property | |
| 60 def android_sdk_path(self): | |
| 61 return self._android_sdk_path | |
| 62 | |
| 63 @property | |
| 64 def android_sdk_build_tools_path(self): | |
| 65 return self._android_sdk_build_tools_path | |
| 66 | |
| 67 @property | |
| 68 def forwarder_host_path(self): | |
| 69 return self._forwarder_host_path | |
| 70 | |
| 71 @property | |
| 72 def forwarder_device_path(self): | |
| 73 return self._forwarder_device_path | |
| 74 | |
| 75 @property | |
| 76 def md5sum_host_path(self): | |
| 77 return self._md5sum_host_path | |
| 78 | |
| 79 @property | |
| 80 def md5sum_device_path(self): | |
| 81 return self._md5sum_device_path | |
| 82 | |
| 83 @property | |
| 84 def pymock_path(self): | |
| 85 return self._pymock_path | |
| 86 | |
| 87 | |
| 88 _env_init_lock = threading.Lock() | |
| 89 | |
| 90 def Initialize(config_files): | |
| 91 with _env_init_lock: | |
| 92 global instance # pylint: disable=global-statement | |
| 93 if not instance: | |
| 94 instance = _Environment(config_files) | |
| 95 | |
| 96 def InitializeForTests(): | |
| 97 test_configs = [ | |
| 98 os.path.abspath(os.path.join( | |
| 99 os.path.dirname(__file__), os.pardir, 'devil_config.json')) | |
| 100 ] | |
| 101 Initialize(test_configs) | |
| 102 | |
| 103 def GenerateDynamicConfig(deps): | |
| 104 return { | |
| 105 'config_type': 'BaseConfig', | |
| 106 'dependencies': { | |
| 107 k: { | |
| 108 'file_info': { | |
| 109 'linux_android': { | |
| 110 'local_paths': v | |
| 111 } | |
| 112 } | |
| 113 } for k, v in deps.iteritems() | |
| 114 } | |
| 115 } | |
| OLD | NEW |