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

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

Issue 2636553002: [build/android] Update adb_command_line.py to use flag_changer (Closed)
Patch Set: Created 3 years, 11 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 | « build/android/adb_chrome_public_command_line ('k') | no next file » | 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 os 9 import os
10 import posixpath
10 import sys 11 import sys
11 12
12 import devil_chromium 13 import devil_chromium
13 14
14 from devil.android import device_utils 15 from devil.android import device_utils
15 from devil.android import device_errors 16 from devil.android import flag_changer
16 from devil.utils import cmd_helper 17 from devil.utils import cmd_helper
17 18
18 19
19 def main(): 20 def main():
20 parser = argparse.ArgumentParser(description=__doc__) 21 parser = argparse.ArgumentParser(description=__doc__)
21 parser.usage = '''%(prog)s --device-path PATH [--device SERIAL] [flags...] 22 parser.usage = '''%(prog)s [--filename FILENAME] [--device SERIAL] [flags...]
22 23
23 No flags: Prints existing command-line file. 24 No flags: Prints existing command-line file.
24 Empty string: Deletes command-line file. 25 Empty string: Deletes command-line file.
25 Otherwise: Writes command-line file. 26 Otherwise: Writes command-line file.
26 27
27 ''' 28 '''
28 parser.add_argument('-d', '--device', dest='devices', action='append', 29 parser.add_argument('-d', '--device', dest='devices', action='append',
29 default=[], help='Target device serial (repeatable).') 30 default=[], help='Target device serial (repeatable).')
30 parser.add_argument('--device-path', required=True, 31 parser.add_argument('--filename', default='chrome-command-line',
jbudorick 2017/01/13 20:50:00 Why'd you make this a default as opposed to having
perezju 2017/01/16 14:48:20 Ok. Changed. Also found more wrapping scripts that
31 help='Remote path to flags file.') 32 help='Name of file where to store flags on the device'
33 ' (default: %(default)s).')
34 parser.add_argument('--device-path', help='(deprecated) No longer needed to'
35 ' supply a device path.')
32 parser.add_argument('-e', '--executable', dest='executable', default='chrome', 36 parser.add_argument('-e', '--executable', dest='executable', default='chrome',
33 help='Name of the executable.') 37 help='(deprecated) No longer used.')
34 parser.add_argument('--adb-path', type=os.path.abspath, 38 parser.add_argument('--adb-path', type=os.path.abspath,
35 help='Path to the adb binary.') 39 help='Path to the adb binary.')
36 args, remote_args = parser.parse_known_args() 40 args, remote_args = parser.parse_known_args()
37 41
42 if args.device_path:
43 args.filename = posixpath.basename(args.device_path)
44 print ('warning: --device-path option is deprecated,'
45 ' --filename %s is now enough.'
46 % cmd_helper.SingleQuote(args.filename))
47
38 devil_chromium.Initialize(adb_path=args.adb_path) 48 devil_chromium.Initialize(adb_path=args.adb_path)
39 49
40 as_root = not args.device_path.startswith('/data/local/tmp/')
41
42 devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices, 50 devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices,
43 default_retries=0) 51 default_retries=0)
44 all_devices = device_utils.DeviceUtils.parallel(devices) 52 all_devices = device_utils.DeviceUtils.parallel(devices)
45 53
46 def print_args(): 54 if not remote_args:
47 def read_flags(device): 55 # No args == do not update, just print flags.
48 try: 56 remote_args = None
49 return device.ReadFile(args.device_path, as_root=as_root).rstrip() 57 action = ''
50 except device_errors.CommandFailedError: 58 elif len(remote_args) == 1 and not remote_args[0]:
51 return '' # File might not exist. 59 # Single empty string arg == delete flags
60 remote_args = []
61 action = 'Deleted flags. '
62 else:
63 action = 'Updated flags. '
52 64
53 descriptions = all_devices.pMap(lambda d: d.build_description).pGet(None) 65 def update_flags(device):
54 flags = all_devices.pMap(read_flags).pGet(None) 66 changer = flag_changer.FlagChanger(device, args.filename)
55 for d, desc, flags in zip(devices, descriptions, flags): 67 if remote_args is not None:
56 print ' %s (%s): %r' % (d, desc, flags) 68 changer.ReplaceFlags(remote_args)
69 return (device, device.build_description, changer.GetCurrentFlags())
57 70
58 # No args == print flags. 71 updated_values = all_devices.pMap(update_flags).pGet(None)
59 if not remote_args:
60 print 'Existing flags (in %s):' % args.device_path
61 print_args()
62 return 0
63 72
64 # Empty string arg == delete flags file. 73 print '%sCurrent flags (in %s):' % (action, args.filename)
65 if len(remote_args) == 1 and not remote_args[0]: 74 for d, desc, flags in updated_values:
jbudorick 2017/01/13 20:49:59 Nice!
66 def delete_flags(device): 75 if flags:
67 device.RunShellCommand(['rm', '-f', args.device_path], as_root=as_root) 76 # Shell-quote flags for easy copy/paste as new args on the terminal.
68 all_devices.pMap(delete_flags).pGet(None) 77 quoted_flags = ' '.join(cmd_helper.SingleQuote(f) for f in flags)
69 print 'Deleted %s' % args.device_path 78 else:
70 return 0 79 quoted_flags = '( empty )'
71 80 print ' %s (%s): %r' % (d, desc, quoted_flags)
72 # Set flags.
73 quoted_args = ' '.join(cmd_helper.SingleQuote(x) for x in remote_args)
74 flags_str = ' '.join([args.executable, quoted_args])
75
76 def write_flags(device):
77 device.WriteFile(args.device_path, flags_str, as_root=as_root)
78 device.RunShellCommand(['chmod', '0664', args.device_path], as_root=as_root)
79
80 all_devices.pMap(write_flags).pGet(None)
81 print 'Wrote flags to %s' % args.device_path
82 print_args()
83 return 0
jbudorick 2017/01/13 20:50:00 nit: this should still return 0
perezju 2017/01/16 14:48:20 Done.
84 81
85 82
86 if __name__ == '__main__': 83 if __name__ == '__main__':
87 sys.exit(main()) 84 sys.exit(main())
OLDNEW
« no previous file with comments | « build/android/adb_chrome_public_command_line ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698