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 |
11 import sys | 11 import sys |
12 | 12 |
13 from pylib import android_commands | 13 from pylib import android_commands |
14 from pylib import constants | 14 from pylib import constants |
15 from pylib.device import device_utils | 15 from pylib.device import device_utils |
16 from pylib.utils import apk_helper | 16 from pylib.utils import apk_helper |
17 | 17 |
18 | 18 |
19 def AddInstallAPKOption(option_parser): | 19 def AddInstallAPKOption(option_parser): |
20 """Adds apk option used to install the APK to the OptionParser.""" | 20 """Adds apk option used to install the APK to the OptionParser.""" |
21 option_parser.add_option('--apk', | 21 option_parser.add_option('--apk', |
22 help=('The name of the apk containing the ' | 22 help=('DEPRECATED The name of the apk containing the' |
Nico
2015/07/23 17:14:15
I happened to look at this file today and see this
jbudorick
2015/07/23 17:28:49
I believe there are multiple reasons for doing thi
| |
23 ' application (with the .apk extension).')) | 23 ' application (with the .apk extension).')) |
24 option_parser.add_option('--apk_package', | 24 option_parser.add_option('--apk_package', |
25 help=('The package name used by the apk containing ' | 25 help=('The package name used by the apk containing ' |
26 'the application.')) | 26 'the application.')) |
27 option_parser.add_option('--keep_data', | 27 option_parser.add_option('--keep_data', |
28 action='store_true', | 28 action='store_true', |
29 default=False, | 29 default=False, |
30 help=('Keep the package data when installing ' | 30 help=('Keep the package data when installing ' |
31 'the application.')) | 31 'the application.')) |
32 option_parser.add_option('--debug', action='store_const', const='Debug', | 32 option_parser.add_option('--debug', action='store_const', const='Debug', |
33 dest='build_type', | 33 dest='build_type', |
34 default=os.environ.get('BUILDTYPE', 'Debug'), | 34 default=os.environ.get('BUILDTYPE', 'Debug'), |
35 help='If set, run test suites under out/Debug. ' | 35 help='If set, run test suites under out/Debug. ' |
36 'Default is env var BUILDTYPE or Debug') | 36 'Default is env var BUILDTYPE or Debug') |
37 option_parser.add_option('--release', action='store_const', const='Release', | 37 option_parser.add_option('--release', action='store_const', const='Release', |
38 dest='build_type', | 38 dest='build_type', |
39 help='If set, run test suites under out/Release. ' | 39 help='If set, run test suites under out/Release. ' |
40 'Default is env var BUILDTYPE or Debug.') | 40 'Default is env var BUILDTYPE or Debug.') |
41 | 41 |
42 | 42 |
43 def ValidateInstallAPKOption(option_parser, options): | 43 def ValidateInstallAPKOption(option_parser, options, args): |
44 """Validates the apk option and potentially qualifies the path.""" | 44 """Validates the apk option and potentially qualifies the path.""" |
45 if not options.apk: | 45 if not options.apk: |
46 option_parser.error('--apk is mandatory.') | 46 if len(args) > 1: |
47 options.apk = args[1] | |
48 else: | |
49 option_parser.error('apk target not specified.') | |
50 | |
51 if not options.apk.endswith('.apk'): | |
52 options.apk += '.apk' | |
53 | |
47 if not os.path.exists(options.apk): | 54 if not os.path.exists(options.apk): |
48 options.apk = os.path.join(constants.GetOutDirectory(), 'apks', | 55 options.apk = os.path.join(constants.GetOutDirectory(), 'apks', |
49 options.apk) | 56 options.apk) |
50 | 57 |
51 | 58 |
52 def main(argv): | 59 def main(argv): |
53 parser = optparse.OptionParser() | 60 parser = optparse.OptionParser() |
61 parser.set_usage("usage: %prog [options] target") | |
54 AddInstallAPKOption(parser) | 62 AddInstallAPKOption(parser) |
55 options, args = parser.parse_args(argv) | 63 options, args = parser.parse_args(argv) |
64 | |
65 if len(args) > 1 and options.apk: | |
66 parser.error("Appending the apk as argument can't be used with --apk.") | |
67 elif len(args) > 2: | |
68 parser.error("Too many arguments.") | |
69 | |
56 constants.SetBuildType(options.build_type) | 70 constants.SetBuildType(options.build_type) |
57 ValidateInstallAPKOption(parser, options) | 71 ValidateInstallAPKOption(parser, options, args) |
58 if len(args) > 1: | |
59 raise Exception('Error: Unknown argument:', args[1:]) | |
60 | 72 |
61 devices = android_commands.GetAttachedDevices() | 73 devices = android_commands.GetAttachedDevices() |
62 if not devices: | 74 if not devices: |
63 raise Exception('Error: no connected devices') | 75 raise Exception('Error: no connected devices') |
64 | 76 |
65 if not options.apk_package: | 77 if not options.apk_package: |
66 options.apk_package = apk_helper.GetPackageName(options.apk) | 78 options.apk_package = apk_helper.GetPackageName(options.apk) |
67 | 79 |
68 device_utils.DeviceUtils.parallel(devices).old_interface.ManagedInstall( | 80 device_utils.DeviceUtils.parallel(devices).old_interface.ManagedInstall( |
69 options.apk, options.keep_data, options.apk_package).pFinish(None) | 81 options.apk, options.keep_data, options.apk_package).pFinish(None) |
70 | 82 |
71 | 83 |
72 if __name__ == '__main__': | 84 if __name__ == '__main__': |
73 sys.exit(main(sys.argv)) | 85 sys.exit(main(sys.argv)) |
74 | 86 |
OLD | NEW |