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 constants | 13 from pylib import constants |
14 from pylib.device import adb_wrapper | |
15 from pylib.device import device_filter | |
16 from pylib.device import device_utils | 14 from pylib.device import device_utils |
17 | 15 |
18 | 16 |
19 def AddInstallAPKOption(option_parser): | 17 def AddInstallAPKOption(option_parser): |
20 """Adds apk option used to install the APK to the OptionParser.""" | 18 """Adds apk option used to install the APK to the OptionParser.""" |
21 option_parser.add_option('--apk', | 19 option_parser.add_option('--apk', |
22 help=('DEPRECATED The name of the apk containing the' | 20 help=('DEPRECATED The name of the apk containing the' |
23 ' application (with the .apk extension).')) | 21 ' application (with the .apk extension).')) |
24 option_parser.add_option('--apk_package', | 22 option_parser.add_option('--apk_package', |
25 help=('DEPRECATED The package name used by the apk ' | 23 help=('DEPRECATED The package name used by the apk ' |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 options, args = parser.parse_args(argv) | 63 options, args = parser.parse_args(argv) |
66 | 64 |
67 if len(args) > 1 and options.apk: | 65 if len(args) > 1 and options.apk: |
68 parser.error("Appending the apk as argument can't be used with --apk.") | 66 parser.error("Appending the apk as argument can't be used with --apk.") |
69 elif len(args) > 2: | 67 elif len(args) > 2: |
70 parser.error("Too many arguments.") | 68 parser.error("Too many arguments.") |
71 | 69 |
72 constants.SetBuildType(options.build_type) | 70 constants.SetBuildType(options.build_type) |
73 ValidateInstallAPKOption(parser, options, args) | 71 ValidateInstallAPKOption(parser, options, args) |
74 | 72 |
75 devices = adb_wrapper.AdbWrapper.Devices( | 73 devices = device_utils.DeviceUtils.HealthyDevices() |
76 filters=device_filter.DefaultFilters()) | |
77 | 74 |
78 if options.device: | 75 if options.device: |
79 if options.device not in [d.GetDeviceSerial() for d in devices]: | 76 device_serials = [d.adb.GetDeviceSerial() for d in devices] |
| 77 if options.device not in device_serials: |
80 raise Exception('Error: %s not in attached devices %s' % (options.device, | 78 raise Exception('Error: %s not in attached devices %s' % (options.device, |
81 ','.join(devices))) | 79 ','.join(device_serials))) |
82 devices = [options.device] | 80 devices = [options.device] |
83 | 81 |
84 if not devices: | 82 if not devices: |
85 raise Exception('Error: no connected devices') | 83 raise Exception('Error: no connected devices') |
86 | 84 |
87 device_utils.DeviceUtils.parallel(devices).Install( | 85 device_utils.DeviceUtils.parallel(devices).Install( |
88 options.apk, reinstall=options.keep_data) | 86 options.apk, reinstall=options.keep_data) |
89 | 87 |
90 | 88 |
91 if __name__ == '__main__': | 89 if __name__ == '__main__': |
92 sys.exit(main(sys.argv)) | 90 sys.exit(main(sys.argv)) |
93 | 91 |
OLD | NEW |