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

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

Issue 1469143002: Refactor adb_*_command_line helpers bash->python (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review nits Created 5 years 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
OLDNEW
(Empty)
1 #!/usr/bin/python
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
4 # found in the LICENSE file.
5
6 """Utility for reading / writing command-line flag files on device(s)."""
7
8 import argparse
9 import sys
10
11 from devil.android import device_utils
12 from devil.android import device_errors
13 from devil.utils import cmd_helper
14
15
16 def main():
17 parser = argparse.ArgumentParser(description=__doc__)
18 parser.usage = '''%(prog)s --device-path PATH [--device SERIAL] [flags...]
19
20 No flags: Prints existing command-line file.
21 Empty string: Deletes command-line file.
22 Otherwise: Writes command-line file.
23
24 '''
25 parser.add_argument('-d', '--device', dest='device',
26 help='Target device for apk to install on.')
27 parser.add_argument('--device-path', required=True,
28 help='Remote path to flags file.')
29 args, remote_args = parser.parse_known_args()
30
31 as_root = not args.device_path.startswith('/data/local/tmp/')
32
33 if args.device:
34 devices = [device_utils.DeviceUtils(args.device, default_retries=0)]
35 else:
36 devices = device_utils.DeviceUtils.HealthyDevices(default_retries=0)
37 if not devices:
38 raise device_errors.NoDevicesError()
39
40 all_devices = device_utils.DeviceUtils.parallel(devices)
41
42 def print_args():
43 def read_flags(device):
44 try:
45 return device.ReadFile(args.device_path, as_root=as_root)
46 except device_errors.AdbCommandFailedError:
47 return '\n' # File might not exist.
48
49 descriptions = all_devices.pMap(lambda d: d.build_description).pGet(None)
50 flags = all_devices.pMap(read_flags).pGet(None)
51 for d, desc, flags in zip(devices, descriptions, flags):
52 print ' %s (%s): %s' % (d, desc, flags),
53
54 # No args == print flags.
55 if not remote_args:
56 print 'Existing flags (in %s):' % args.device_path
57 print_args()
58 return 0
59
60 # Empty string arg == delete flags file.
61 if len(remote_args) == 1 and not remote_args[0]:
62 def delete_flags(device):
63 device.RunShellCommand(['rm', '-f', args.device_path], as_root=as_root)
64 all_devices.pMap(delete_flags).pGet(None)
65 print 'Deleted %s' % args.device_path
66 return 0
67
68 # Set flags.
69 quoted_args = ' '.join(cmd_helper.SingleQuote(x) for x in remote_args)
70 flags_str = 'chrome %s' % quoted_args
71
72 def write_flags(device):
73 device.WriteFile(args.device_path, flags_str, as_root=as_root)
74 device.RunShellCommand(['chmod', '0664', args.device_path], as_root=as_root)
75
76 all_devices.pMap(write_flags).pGet(None)
77 print 'Wrote flags to %s' % args.device_path
78 print_args()
79 return 0
80
81
82 if __name__ == '__main__':
83 sys.exit(main())
OLDNEW
« no previous file with comments | « build/android/adb_chrome_public_command_line ('k') | build/android/adb_command_line_functions.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698