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 import multiprocessing | 7 import multiprocessing |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import sys | 10 import sys |
11 | 11 |
12 from pylib import android_commands | 12 from pylib import android_commands |
| 13 from pylib import apk_info |
| 14 from pylib import constants |
13 from pylib import test_options_parser | 15 from pylib import test_options_parser |
14 from pylib import constants | |
15 | 16 |
16 | 17 |
17 def InstallApk(args): | 18 def _InstallApk(args): |
18 options, device = args | 19 apk_path, apk_package, device = args |
19 apk_path = os.path.join(os.environ['CHROME_SRC'], | |
20 'out', options.build_type, | |
21 'apks', options.apk) | |
22 result = android_commands.AndroidCommands(device=device).ManagedInstall( | 20 result = android_commands.AndroidCommands(device=device).ManagedInstall( |
23 apk_path, False, options.apk_package) | 21 apk_path, False, apk_package) |
24 print '----- Installed on %s -----' % device | 22 print '----- Installed on %s -----' % device |
25 print result | 23 print result |
26 | 24 |
27 | 25 |
28 def main(argv): | 26 def main(argv): |
29 parser = optparse.OptionParser() | 27 parser = optparse.OptionParser() |
30 test_options_parser.AddBuildTypeOption(parser) | 28 test_options_parser.AddBuildTypeOption(parser) |
31 test_options_parser.AddInstallAPKOption(parser) | 29 test_options_parser.AddInstallAPKOption(parser) |
32 options, args = parser.parse_args(argv) | 30 options, args = parser.parse_args(argv) |
33 | 31 test_options_parser.ValidateInstallAPKOption(options) |
34 if len(args) > 1: | 32 if len(args) > 1: |
35 raise Exception('Error: Unknown argument:', args[1:]) | 33 raise Exception('Error: Unknown argument:', args[1:]) |
36 | 34 |
37 devices = android_commands.GetAttachedDevices() | 35 devices = android_commands.GetAttachedDevices() |
38 if not devices: | 36 if not devices: |
39 raise Exception('Error: no connected devices') | 37 raise Exception('Error: no connected devices') |
40 | 38 |
| 39 if not options.apk_package: |
| 40 options.apk_package = apk_info.GetPackageNameForApk(options.apk) |
| 41 |
41 pool = multiprocessing.Pool(len(devices)) | 42 pool = multiprocessing.Pool(len(devices)) |
42 # Send a tuple (options, device) per instance of DeploySingleDevice. | 43 # Send a tuple (apk_path, apk_package, device) per device. |
43 pool.map(InstallApk, zip([options] * len(devices), devices)) | 44 pool.map(_InstallApk, zip([options.apk] * len(devices), |
| 45 [options.apk_package] * len(devices), |
| 46 devices)) |
44 | 47 |
45 | 48 |
46 if __name__ == '__main__': | 49 if __name__ == '__main__': |
47 sys.exit(main(sys.argv)) | 50 sys.exit(main(sys.argv)) |
OLD | NEW |