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