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 multiprocessing | |
10 import optparse | 9 import optparse |
11 import os | 10 import os |
12 import sys | 11 import sys |
13 | 12 |
14 from pylib import android_commands | 13 from pylib import android_commands |
15 from pylib import constants | 14 from pylib import constants |
16 from pylib.device import device_utils | 15 from pylib.device import device_utils |
17 from pylib.utils import apk_helper | 16 from pylib.utils import apk_helper |
18 | 17 |
19 | 18 |
(...skipping 23 matching lines...) Expand all Loading... |
43 | 42 |
44 def ValidateInstallAPKOption(option_parser, options): | 43 def ValidateInstallAPKOption(option_parser, options): |
45 """Validates the apk option and potentially qualifies the path.""" | 44 """Validates the apk option and potentially qualifies the path.""" |
46 if not options.apk: | 45 if not options.apk: |
47 option_parser.error('--apk is mandatory.') | 46 option_parser.error('--apk is mandatory.') |
48 if not os.path.exists(options.apk): | 47 if not os.path.exists(options.apk): |
49 options.apk = os.path.join(constants.GetOutDirectory(), 'apks', | 48 options.apk = os.path.join(constants.GetOutDirectory(), 'apks', |
50 options.apk) | 49 options.apk) |
51 | 50 |
52 | 51 |
53 def _InstallApk(args): | |
54 apk_path, apk_package, keep_data, device = args | |
55 device_utils.DeviceUtils(device=device).old_interface.ManagedInstall( | |
56 apk_path, keep_data, apk_package) | |
57 print '----- Installed on %s -----' % device | |
58 | |
59 | |
60 def main(argv): | 52 def main(argv): |
61 parser = optparse.OptionParser() | 53 parser = optparse.OptionParser() |
62 AddInstallAPKOption(parser) | 54 AddInstallAPKOption(parser) |
63 options, args = parser.parse_args(argv) | 55 options, args = parser.parse_args(argv) |
64 constants.SetBuildType(options.build_type) | 56 constants.SetBuildType(options.build_type) |
65 ValidateInstallAPKOption(parser, options) | 57 ValidateInstallAPKOption(parser, options) |
66 if len(args) > 1: | 58 if len(args) > 1: |
67 raise Exception('Error: Unknown argument:', args[1:]) | 59 raise Exception('Error: Unknown argument:', args[1:]) |
68 | 60 |
69 devices = android_commands.GetAttachedDevices() | 61 devices = android_commands.GetAttachedDevices() |
70 if not devices: | 62 if not devices: |
71 raise Exception('Error: no connected devices') | 63 raise Exception('Error: no connected devices') |
72 | 64 |
73 if not options.apk_package: | 65 if not options.apk_package: |
74 options.apk_package = apk_helper.GetPackageName(options.apk) | 66 options.apk_package = apk_helper.GetPackageName(options.apk) |
75 | 67 |
76 pool = multiprocessing.Pool(len(devices)) | 68 device_utils.DeviceUtils.parallel(devices).old_interface.ManagedInstall( |
77 # Send a tuple (apk_path, apk_package, device) per device. | 69 options.apk, options.keep_data, options.apk_package).pFinish(None) |
78 pool.map(_InstallApk, zip([options.apk] * len(devices), | |
79 [options.apk_package] * len(devices), | |
80 [options.keep_data] * len(devices), | |
81 devices)) | |
82 | 70 |
83 | 71 |
84 if __name__ == '__main__': | 72 if __name__ == '__main__': |
85 sys.exit(main(sys.argv)) | 73 sys.exit(main(sys.argv)) |
| 74 |
OLD | NEW |