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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/adb_chrome_public_command_line ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/adb_command_line.py
diff --git a/build/android/adb_command_line.py b/build/android/adb_command_line.py
index 948bc8944492b088922fac874322c87b95d253a2..1093382c083a90126a15d83b5d72da5dcfce217a 100755
--- a/build/android/adb_command_line.py
+++ b/build/android/adb_command_line.py
@@ -7,18 +7,19 @@
import argparse
import os
+import posixpath
import sys
import devil_chromium
from devil.android import device_utils
-from devil.android import device_errors
+from devil.android import flag_changer
from devil.utils import cmd_helper
def main():
parser = argparse.ArgumentParser(description=__doc__)
- parser.usage = '''%(prog)s --device-path PATH [--device SERIAL] [flags...]
+ parser.usage = '''%(prog)s [--filename FILENAME] [--device SERIAL] [flags...]
No flags: Prints existing command-line file.
Empty string: Deletes command-line file.
@@ -27,60 +28,56 @@ Otherwise: Writes command-line file.
'''
parser.add_argument('-d', '--device', dest='devices', action='append',
default=[], help='Target device serial (repeatable).')
- parser.add_argument('--device-path', required=True,
- help='Remote path to flags file.')
+ 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
+ help='Name of file where to store flags on the device'
+ ' (default: %(default)s).')
+ parser.add_argument('--device-path', help='(deprecated) No longer needed to'
+ ' supply a device path.')
parser.add_argument('-e', '--executable', dest='executable', default='chrome',
- help='Name of the executable.')
+ help='(deprecated) No longer used.')
parser.add_argument('--adb-path', type=os.path.abspath,
help='Path to the adb binary.')
args, remote_args = parser.parse_known_args()
- devil_chromium.Initialize(adb_path=args.adb_path)
+ if args.device_path:
+ args.filename = posixpath.basename(args.device_path)
+ print ('warning: --device-path option is deprecated,'
+ ' --filename %s is now enough.'
+ % cmd_helper.SingleQuote(args.filename))
- as_root = not args.device_path.startswith('/data/local/tmp/')
+ devil_chromium.Initialize(adb_path=args.adb_path)
devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices,
default_retries=0)
all_devices = device_utils.DeviceUtils.parallel(devices)
- def print_args():
- def read_flags(device):
- try:
- return device.ReadFile(args.device_path, as_root=as_root).rstrip()
- except device_errors.CommandFailedError:
- return '' # File might not exist.
-
- descriptions = all_devices.pMap(lambda d: d.build_description).pGet(None)
- flags = all_devices.pMap(read_flags).pGet(None)
- for d, desc, flags in zip(devices, descriptions, flags):
- print ' %s (%s): %r' % (d, desc, flags)
-
- # No args == print flags.
if not remote_args:
- print 'Existing flags (in %s):' % args.device_path
- print_args()
- return 0
-
- # Empty string arg == delete flags file.
- if len(remote_args) == 1 and not remote_args[0]:
- def delete_flags(device):
- device.RunShellCommand(['rm', '-f', args.device_path], as_root=as_root)
- all_devices.pMap(delete_flags).pGet(None)
- print 'Deleted %s' % args.device_path
- return 0
-
- # Set flags.
- quoted_args = ' '.join(cmd_helper.SingleQuote(x) for x in remote_args)
- flags_str = ' '.join([args.executable, quoted_args])
-
- def write_flags(device):
- device.WriteFile(args.device_path, flags_str, as_root=as_root)
- device.RunShellCommand(['chmod', '0664', args.device_path], as_root=as_root)
-
- all_devices.pMap(write_flags).pGet(None)
- print 'Wrote flags to %s' % args.device_path
- print_args()
- return 0
jbudorick 2017/01/13 20:50:00 nit: this should still return 0
perezju 2017/01/16 14:48:20 Done.
+ # No args == do not update, just print flags.
+ remote_args = None
+ action = ''
+ elif len(remote_args) == 1 and not remote_args[0]:
+ # Single empty string arg == delete flags
+ remote_args = []
+ action = 'Deleted flags. '
+ else:
+ action = 'Updated flags. '
+
+ def update_flags(device):
+ changer = flag_changer.FlagChanger(device, args.filename)
+ if remote_args is not None:
+ changer.ReplaceFlags(remote_args)
+ return (device, device.build_description, changer.GetCurrentFlags())
+
+ updated_values = all_devices.pMap(update_flags).pGet(None)
+
+ print '%sCurrent flags (in %s):' % (action, args.filename)
+ for d, desc, flags in updated_values:
jbudorick 2017/01/13 20:49:59 Nice!
+ if flags:
+ # Shell-quote flags for easy copy/paste as new args on the terminal.
+ quoted_flags = ' '.join(cmd_helper.SingleQuote(f) for f in flags)
+ else:
+ quoted_flags = '( empty )'
+ print ' %s (%s): %r' % (d, desc, quoted_flags)
if __name__ == '__main__':
« 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