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 | 9 import multiprocessing |
10 import optparse | 10 import optparse |
(...skipping 27 matching lines...) Expand all Loading... |
38 if not options.apk: | 38 if not options.apk: |
39 option_parser.error('--apk is mandatory.') | 39 option_parser.error('--apk is mandatory.') |
40 if not os.path.exists(options.apk): | 40 if not os.path.exists(options.apk): |
41 options.apk = os.path.join(constants.DIR_SOURCE_ROOT, | 41 options.apk = os.path.join(constants.DIR_SOURCE_ROOT, |
42 'out', options.build_type, | 42 'out', options.build_type, |
43 'apks', options.apk) | 43 'apks', options.apk) |
44 | 44 |
45 | 45 |
46 def _InstallApk(args): | 46 def _InstallApk(args): |
47 apk_path, apk_package, keep_data, device = args | 47 apk_path, apk_package, keep_data, device = args |
48 result = android_commands.AndroidCommands(device=device).ManagedInstall( | 48 android_commands.AndroidCommands(device=device).ManagedInstall( |
49 apk_path, keep_data, apk_package) | 49 apk_path, keep_data, apk_package) |
50 print '----- Installed on %s -----' % device | 50 print '----- Installed on %s -----' % device |
51 print result | |
52 | 51 |
53 | 52 |
54 def main(argv): | 53 def main(argv): |
55 parser = optparse.OptionParser() | 54 parser = optparse.OptionParser() |
56 AddInstallAPKOption(parser) | 55 AddInstallAPKOption(parser) |
57 options, args = parser.parse_args(argv) | 56 options, args = parser.parse_args(argv) |
58 ValidateInstallAPKOption(parser, options) | 57 ValidateInstallAPKOption(parser, options) |
59 if len(args) > 1: | 58 if len(args) > 1: |
60 raise Exception('Error: Unknown argument:', args[1:]) | 59 raise Exception('Error: Unknown argument:', args[1:]) |
61 | 60 |
62 devices = android_commands.GetAttachedDevices() | 61 devices = android_commands.GetAttachedDevices() |
63 if not devices: | 62 if not devices: |
64 raise Exception('Error: no connected devices') | 63 raise Exception('Error: no connected devices') |
65 | 64 |
66 if not options.apk_package: | 65 if not options.apk_package: |
67 options.apk_package = apk_helper.GetPackageName(options.apk) | 66 options.apk_package = apk_helper.GetPackageName(options.apk) |
68 | 67 |
69 pool = multiprocessing.Pool(len(devices)) | 68 pool = multiprocessing.Pool(len(devices)) |
70 # Send a tuple (apk_path, apk_package, device) per device. | 69 # Send a tuple (apk_path, apk_package, device) per device. |
71 pool.map(_InstallApk, zip([options.apk] * len(devices), | 70 pool.map(_InstallApk, zip([options.apk] * len(devices), |
72 [options.apk_package] * len(devices), | 71 [options.apk_package] * len(devices), |
73 [options.keep_data] * len(devices), | 72 [options.keep_data] * len(devices), |
74 devices)) | 73 devices)) |
75 | 74 |
76 | 75 |
77 if __name__ == '__main__': | 76 if __name__ == '__main__': |
78 sys.exit(main(sys.argv)) | 77 sys.exit(main(sys.argv)) |
OLD | NEW |