Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: build/android/adb_command_line.py

Issue 1895163002: 🐠 Use the new DeviceUtils.HealthyDevices(device_arg=) in a few scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/android/adb_install_apk.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Utility for reading / writing command-line flag files on device(s).""" 6 """Utility for reading / writing command-line flag files on device(s)."""
7 7
8 import argparse 8 import argparse
9 import sys 9 import sys
10 10
11 import devil_chromium 11 import devil_chromium
12 12
13 from devil.android import device_utils 13 from devil.android import device_utils
14 from devil.android import device_errors 14 from devil.android import device_errors
15 from devil.utils import cmd_helper 15 from devil.utils import cmd_helper
16 16
17 17
18 def main(): 18 def main():
19 parser = argparse.ArgumentParser(description=__doc__) 19 parser = argparse.ArgumentParser(description=__doc__)
20 parser.usage = '''%(prog)s --device-path PATH [--device SERIAL] [flags...] 20 parser.usage = '''%(prog)s --device-path PATH [--device SERIAL] [flags...]
21 21
22 No flags: Prints existing command-line file. 22 No flags: Prints existing command-line file.
23 Empty string: Deletes command-line file. 23 Empty string: Deletes command-line file.
24 Otherwise: Writes command-line file. 24 Otherwise: Writes command-line file.
25 25
26 ''' 26 '''
27 parser.add_argument('-d', '--device', dest='device', 27 parser.add_argument('-d', '--device', dest='devices', action='append',
28 help='Target device for apk to install on.') 28 default=[], help='Target device serial (repeatable).')
29 parser.add_argument('--device-path', required=True, 29 parser.add_argument('--device-path', required=True,
30 help='Remote path to flags file.') 30 help='Remote path to flags file.')
31 parser.add_argument('-e', '--executable', dest='executable', default='chrome', 31 parser.add_argument('-e', '--executable', dest='executable', default='chrome',
32 help='Name of the executable.') 32 help='Name of the executable.')
33 args, remote_args = parser.parse_known_args() 33 args, remote_args = parser.parse_known_args()
34 34
35 devil_chromium.Initialize() 35 devil_chromium.Initialize()
36 36
37 as_root = not args.device_path.startswith('/data/local/tmp/') 37 as_root = not args.device_path.startswith('/data/local/tmp/')
38 38
39 if args.device: 39 devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices,
40 devices = [device_utils.DeviceUtils(args.device, default_retries=0)] 40 default_retries=0)
41 else:
42 devices = device_utils.DeviceUtils.HealthyDevices(default_retries=0)
43 if not devices:
44 raise device_errors.NoDevicesError()
45
46 all_devices = device_utils.DeviceUtils.parallel(devices) 41 all_devices = device_utils.DeviceUtils.parallel(devices)
47 42
48 def print_args(): 43 def print_args():
49 def read_flags(device): 44 def read_flags(device):
50 try: 45 try:
51 return device.ReadFile(args.device_path, as_root=as_root).rstrip() 46 return device.ReadFile(args.device_path, as_root=as_root).rstrip()
52 except device_errors.AdbCommandFailedError: 47 except device_errors.AdbCommandFailedError:
53 return '' # File might not exist. 48 return '' # File might not exist.
54 49
55 descriptions = all_devices.pMap(lambda d: d.build_description).pGet(None) 50 descriptions = all_devices.pMap(lambda d: d.build_description).pGet(None)
(...skipping 24 matching lines...) Expand all
80 device.RunShellCommand(['chmod', '0664', args.device_path], as_root=as_root) 75 device.RunShellCommand(['chmod', '0664', args.device_path], as_root=as_root)
81 76
82 all_devices.pMap(write_flags).pGet(None) 77 all_devices.pMap(write_flags).pGet(None)
83 print 'Wrote flags to %s' % args.device_path 78 print 'Wrote flags to %s' % args.device_path
84 print_args() 79 print_args()
85 return 0 80 return 0
86 81
87 82
88 if __name__ == '__main__': 83 if __name__ == '__main__':
89 sys.exit(main()) 84 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/android/adb_install_apk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698