| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Utility script to install APKs from the command line quickly.""" | 7 """Utility script to install APKs from the command line quickly.""" |
| 8 | 8 |
| 9 import optparse | 9 import optparse |
| 10 import os | 10 import os |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 'the application.')) | 30 'the application.')) |
| 31 option_parser.add_option('--debug', action='store_const', const='Debug', | 31 option_parser.add_option('--debug', action='store_const', const='Debug', |
| 32 dest='build_type', | 32 dest='build_type', |
| 33 default=os.environ.get('BUILDTYPE', 'Debug'), | 33 default=os.environ.get('BUILDTYPE', 'Debug'), |
| 34 help='If set, run test suites under out/Debug. ' | 34 help='If set, run test suites under out/Debug. ' |
| 35 'Default is env var BUILDTYPE or Debug') | 35 'Default is env var BUILDTYPE or Debug') |
| 36 option_parser.add_option('--release', action='store_const', const='Release', | 36 option_parser.add_option('--release', action='store_const', const='Release', |
| 37 dest='build_type', | 37 dest='build_type', |
| 38 help='If set, run test suites under out/Release. ' | 38 help='If set, run test suites under out/Release. ' |
| 39 'Default is env var BUILDTYPE or Debug.') | 39 'Default is env var BUILDTYPE or Debug.') |
| 40 option_parser.add_option('-d', '--device', dest='device', |
| 41 help='Target device for apk to install on.') |
| 40 | 42 |
| 41 | 43 |
| 42 def ValidateInstallAPKOption(option_parser, options, args): | 44 def ValidateInstallAPKOption(option_parser, options, args): |
| 43 """Validates the apk option and potentially qualifies the path.""" | 45 """Validates the apk option and potentially qualifies the path.""" |
| 44 if not options.apk: | 46 if not options.apk: |
| 45 if len(args) > 1: | 47 if len(args) > 1: |
| 46 options.apk = args[1] | 48 options.apk = args[1] |
| 47 else: | 49 else: |
| 48 option_parser.error('apk target not specified.') | 50 option_parser.error('apk target not specified.') |
| 49 | 51 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 63 | 65 |
| 64 if len(args) > 1 and options.apk: | 66 if len(args) > 1 and options.apk: |
| 65 parser.error("Appending the apk as argument can't be used with --apk.") | 67 parser.error("Appending the apk as argument can't be used with --apk.") |
| 66 elif len(args) > 2: | 68 elif len(args) > 2: |
| 67 parser.error("Too many arguments.") | 69 parser.error("Too many arguments.") |
| 68 | 70 |
| 69 constants.SetBuildType(options.build_type) | 71 constants.SetBuildType(options.build_type) |
| 70 ValidateInstallAPKOption(parser, options, args) | 72 ValidateInstallAPKOption(parser, options, args) |
| 71 | 73 |
| 72 devices = android_commands.GetAttachedDevices() | 74 devices = android_commands.GetAttachedDevices() |
| 75 |
| 76 if options.device: |
| 77 if options.device not in devices: |
| 78 raise Exception('Error: %s not in attached devices %s' % (options.device, |
| 79 ','.join(devices))) |
| 80 devices = [options.device] |
| 81 |
| 73 if not devices: | 82 if not devices: |
| 74 raise Exception('Error: no connected devices') | 83 raise Exception('Error: no connected devices') |
| 75 | 84 |
| 76 device_utils.DeviceUtils.parallel(devices).Install( | 85 device_utils.DeviceUtils.parallel(devices).Install( |
| 77 options.apk, reinstall=options.keep_data) | 86 options.apk, reinstall=options.keep_data) |
| 78 | 87 |
| 79 | 88 |
| 80 if __name__ == '__main__': | 89 if __name__ == '__main__': |
| 81 sys.exit(main(sys.argv)) | 90 sys.exit(main(sys.argv)) |
| 82 | 91 |
| OLD | NEW |