diff options
Diffstat (limited to 'catapult/devil/devil/android/tools/script_common.py')
-rw-r--r-- | catapult/devil/devil/android/tools/script_common.py | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/catapult/devil/devil/android/tools/script_common.py b/catapult/devil/devil/android/tools/script_common.py index 897659bb..ae2b7a84 100644 --- a/catapult/devil/devil/android/tools/script_common.py +++ b/catapult/devil/devil/android/tools/script_common.py @@ -2,10 +2,11 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import argparse import os from devil import devil_env -from devil.android import device_blacklist +from devil.android import device_denylist from devil.android import device_errors from devil.android import device_utils @@ -20,8 +21,7 @@ def AddEnvironmentArguments(parser): parser: an instance of argparse.ArgumentParser """ parser.add_argument( - '--adb-path', type=os.path.realpath, - help='Path to the adb binary') + '--adb-path', type=os.path.realpath, help='Path to the adb binary') def InitializeEnvironment(args): @@ -46,32 +46,51 @@ def InitializeEnvironment(args): devil_dynamic_config = devil_env.EmptyConfig() if args.adb_path: devil_dynamic_config['dependencies'].update( - devil_env.LocalConfigItem( - 'adb', devil_env.GetPlatform(), args.adb_path)) + devil_env.LocalConfigItem('adb', devil_env.GetPlatform(), + args.adb_path)) devil_env.config.Initialize(configs=[devil_dynamic_config]) def AddDeviceArguments(parser): - """Adds device and blacklist arguments to the provided parser. + """Adds device and denylist arguments to the provided parser. Args: parser: an instance of argparse.ArgumentParser """ parser.add_argument( - '-d', '--device', dest='devices', action='append', + '-d', + '--device', + dest='devices', + action='append', + default=[], help='Serial number of the Android device to use. (default: use all)') - parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') + # TODO(crbug.com/1097306): Simplify this to an ungrouped --denylist-file + # once all uses of --blacklist-file / args.blacklist_file have been updated. + class DenylistAction(argparse.Action): -def GetDevices(requested_devices, blacklist_file): + #override + def __call__(self, parser, namespace, values, option_string=None): + setattr(namespace, 'denylist_file', values) + setattr(namespace, 'blacklist_file', values) + + denylist_group = parser.add_mutually_exclusive_group() + denylist_group.add_argument('--denylist-file', + help='Device denylist JSON file.', + action=DenylistAction) + denylist_group.add_argument('--blacklist-file', + help=argparse.SUPPRESS, + action=DenylistAction) + + +def GetDevices(requested_devices, denylist_file): """Gets a list of healthy devices matching the given parameters.""" - if not isinstance(blacklist_file, device_blacklist.Blacklist): - blacklist_file = (device_blacklist.Blacklist(blacklist_file) - if blacklist_file - else None) + if not isinstance(denylist_file, device_denylist.Denylist): + denylist_file = (device_denylist.Denylist(denylist_file) + if denylist_file else None) - devices = device_utils.DeviceUtils.HealthyDevices(blacklist_file) + devices = device_utils.DeviceUtils.HealthyDevices(denylist_file) if not devices: raise device_errors.NoDevicesError() elif requested_devices: @@ -80,8 +99,7 @@ def GetDevices(requested_devices, blacklist_file): missing = requested.difference(available) if missing: raise device_errors.DeviceUnreachableError(next(iter(missing))) - return sorted(device_utils.DeviceUtils(d) - for d in available.intersection(requested)) + return sorted( + device_utils.DeviceUtils(d) for d in available.intersection(requested)) else: return devices - |