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