| 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 |
| 11 import os | 11 import os |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 from pylib import android_commands | 14 from pylib import android_commands |
| 15 from pylib import constants | 15 from pylib import constants |
| 16 from pylib.device import device_utils |
| 16 from pylib.utils import apk_helper | 17 from pylib.utils import apk_helper |
| 17 from pylib.utils import test_options_parser | 18 from pylib.utils import test_options_parser |
| 18 | 19 |
| 19 | 20 |
| 20 def AddInstallAPKOption(option_parser): | 21 def AddInstallAPKOption(option_parser): |
| 21 """Adds apk option used to install the APK to the OptionParser.""" | 22 """Adds apk option used to install the APK to the OptionParser.""" |
| 22 test_options_parser.AddBuildTypeOption(option_parser) | 23 test_options_parser.AddBuildTypeOption(option_parser) |
| 23 option_parser.add_option('--apk', | 24 option_parser.add_option('--apk', |
| 24 help=('The name of the apk containing the ' | 25 help=('The name of the apk containing the ' |
| 25 ' application (with the .apk extension).')) | 26 ' application (with the .apk extension).')) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 """Validates the apk option and potentially qualifies the path.""" | 38 """Validates the apk option and potentially qualifies the path.""" |
| 38 if not options.apk: | 39 if not options.apk: |
| 39 option_parser.error('--apk is mandatory.') | 40 option_parser.error('--apk is mandatory.') |
| 40 if not os.path.exists(options.apk): | 41 if not os.path.exists(options.apk): |
| 41 options.apk = os.path.join(constants.GetOutDirectory(), 'apks', | 42 options.apk = os.path.join(constants.GetOutDirectory(), 'apks', |
| 42 options.apk) | 43 options.apk) |
| 43 | 44 |
| 44 | 45 |
| 45 def _InstallApk(args): | 46 def _InstallApk(args): |
| 46 apk_path, apk_package, keep_data, device = args | 47 apk_path, apk_package, keep_data, device = args |
| 47 android_commands.AndroidCommands(device=device).ManagedInstall( | 48 device_utils.DeviceUtils(device=device).old_interface.ManagedInstall( |
| 48 apk_path, keep_data, apk_package) | 49 apk_path, keep_data, apk_package) |
| 49 print '----- Installed on %s -----' % device | 50 print '----- Installed on %s -----' % device |
| 50 | 51 |
| 51 | 52 |
| 52 def main(argv): | 53 def main(argv): |
| 53 parser = optparse.OptionParser() | 54 parser = optparse.OptionParser() |
| 54 AddInstallAPKOption(parser) | 55 AddInstallAPKOption(parser) |
| 55 options, args = parser.parse_args(argv) | 56 options, args = parser.parse_args(argv) |
| 56 constants.SetBuildType(options.build_type) | 57 constants.SetBuildType(options.build_type) |
| 57 ValidateInstallAPKOption(parser, options) | 58 ValidateInstallAPKOption(parser, options) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 pool = multiprocessing.Pool(len(devices)) | 69 pool = multiprocessing.Pool(len(devices)) |
| 69 # Send a tuple (apk_path, apk_package, device) per device. | 70 # Send a tuple (apk_path, apk_package, device) per device. |
| 70 pool.map(_InstallApk, zip([options.apk] * len(devices), | 71 pool.map(_InstallApk, zip([options.apk] * len(devices), |
| 71 [options.apk_package] * len(devices), | 72 [options.apk_package] * len(devices), |
| 72 [options.keep_data] * len(devices), | 73 [options.keep_data] * len(devices), |
| 73 devices)) | 74 devices)) |
| 74 | 75 |
| 75 | 76 |
| 76 if __name__ == '__main__': | 77 if __name__ == '__main__': |
| 77 sys.exit(main(sys.argv)) | 78 sys.exit(main(sys.argv)) |
| OLD | NEW |