| OLD | NEW |
| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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='device', |
| 28 help='Target device for apk to install on.') | 28 help='Target device for apk to install on.') |
| 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', |
| 32 help='Name of the executable.') |
| 31 args, remote_args = parser.parse_known_args() | 33 args, remote_args = parser.parse_known_args() |
| 32 | 34 |
| 33 devil_chromium.Initialize() | 35 devil_chromium.Initialize() |
| 34 | 36 |
| 35 as_root = not args.device_path.startswith('/data/local/tmp/') | 37 as_root = not args.device_path.startswith('/data/local/tmp/') |
| 36 | 38 |
| 37 if args.device: | 39 if args.device: |
| 38 devices = [device_utils.DeviceUtils(args.device, default_retries=0)] | 40 devices = [device_utils.DeviceUtils(args.device, default_retries=0)] |
| 39 else: | 41 else: |
| 40 devices = device_utils.DeviceUtils.HealthyDevices(default_retries=0) | 42 devices = device_utils.DeviceUtils.HealthyDevices(default_retries=0) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 64 # Empty string arg == delete flags file. | 66 # Empty string arg == delete flags file. |
| 65 if len(remote_args) == 1 and not remote_args[0]: | 67 if len(remote_args) == 1 and not remote_args[0]: |
| 66 def delete_flags(device): | 68 def delete_flags(device): |
| 67 device.RunShellCommand(['rm', '-f', args.device_path], as_root=as_root) | 69 device.RunShellCommand(['rm', '-f', args.device_path], as_root=as_root) |
| 68 all_devices.pMap(delete_flags).pGet(None) | 70 all_devices.pMap(delete_flags).pGet(None) |
| 69 print 'Deleted %s' % args.device_path | 71 print 'Deleted %s' % args.device_path |
| 70 return 0 | 72 return 0 |
| 71 | 73 |
| 72 # Set flags. | 74 # Set flags. |
| 73 quoted_args = ' '.join(cmd_helper.SingleQuote(x) for x in remote_args) | 75 quoted_args = ' '.join(cmd_helper.SingleQuote(x) for x in remote_args) |
| 74 flags_str = 'chrome %s' % quoted_args | 76 flags_str = ' '.join([args.executable, quoted_args]) |
| 75 | 77 |
| 76 def write_flags(device): | 78 def write_flags(device): |
| 77 device.WriteFile(args.device_path, flags_str, as_root=as_root) | 79 device.WriteFile(args.device_path, flags_str, as_root=as_root) |
| 78 device.RunShellCommand(['chmod', '0664', args.device_path], as_root=as_root) | 80 device.RunShellCommand(['chmod', '0664', args.device_path], as_root=as_root) |
| 79 | 81 |
| 80 all_devices.pMap(write_flags).pGet(None) | 82 all_devices.pMap(write_flags).pGet(None) |
| 81 print 'Wrote flags to %s' % args.device_path | 83 print 'Wrote flags to %s' % args.device_path |
| 82 print_args() | 84 print_args() |
| 83 return 0 | 85 return 0 |
| 84 | 86 |
| 85 | 87 |
| 86 if __name__ == '__main__': | 88 if __name__ == '__main__': |
| 87 sys.exit(main()) | 89 sys.exit(main()) |
| OLD | NEW |