Chromium Code Reviews| 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 argparse | 9 import argparse |
| 10 import glob | |
| 10 import logging | 11 import logging |
| 11 import os | 12 import os |
| 12 import sys | 13 import sys |
| 13 | 14 |
| 14 from pylib import constants | 15 from pylib import constants |
| 15 from pylib.device import device_blacklist | 16 from pylib.device import device_blacklist |
| 16 from pylib.device import device_errors | 17 from pylib.device import device_errors |
| 17 from pylib.device import device_utils | 18 from pylib.device import device_utils |
| 18 from pylib.utils import run_tests_helper | 19 from pylib.utils import run_tests_helper |
| 19 | 20 |
| 20 | |
| 21 def main(): | 21 def main(): |
| 22 parser = argparse.ArgumentParser() | 22 parser = argparse.ArgumentParser() |
| 23 | 23 |
| 24 apk_group = parser.add_mutually_exclusive_group(required=True) | 24 apk_group = parser.add_mutually_exclusive_group(required=True) |
| 25 apk_group.add_argument('--apk', dest='apk_name', | 25 apk_group.add_argument('--apk', dest='apk_name', |
| 26 help='DEPRECATED The name of the apk containing the' | 26 help='DEPRECATED The name of the apk containing the' |
| 27 ' application (with the .apk extension).') | 27 ' application (with the .apk extension).') |
| 28 apk_group.add_argument('apk_path', nargs='?', | 28 apk_group.add_argument('apk_path', nargs='?', |
| 29 help='The path to the APK to install.') | 29 help='The path to the APK to install.') |
| 30 | 30 |
| 31 # TODO(jbudorick): Remove once no clients pass --apk_package | 31 # TODO(jbudorick): Remove once no clients pass --apk_package |
| 32 parser.add_argument('--apk_package', help='DEPRECATED unused') | 32 parser.add_argument('--apk_package', help='DEPRECATED unused') |
| 33 parser.add_argument('--split', | |
| 34 action='store_true', | |
| 35 default=False, | |
| 36 help='Indicates you are installing a split apk.') | |
| 33 parser.add_argument('--keep_data', | 37 parser.add_argument('--keep_data', |
| 34 action='store_true', | 38 action='store_true', |
| 35 default=False, | 39 default=False, |
| 36 help='Keep the package data when installing ' | 40 help='Keep the package data when installing ' |
| 37 'the application.') | 41 'the application.') |
| 38 parser.add_argument('--debug', action='store_const', const='Debug', | 42 parser.add_argument('--debug', action='store_const', const='Debug', |
| 39 dest='build_type', | 43 dest='build_type', |
| 40 default=os.environ.get('BUILDTYPE', 'Debug'), | 44 default=os.environ.get('BUILDTYPE', 'Debug'), |
| 41 help='If set, run test suites under out/Debug. ' | 45 help='If set, run test suites under out/Debug. ' |
| 42 'Default is env var BUILDTYPE or Debug') | 46 'Default is env var BUILDTYPE or Debug') |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 57 apk = args.apk_path or args.apk_name | 61 apk = args.apk_path or args.apk_name |
| 58 if not apk.endswith('.apk'): | 62 if not apk.endswith('.apk'): |
| 59 apk += '.apk' | 63 apk += '.apk' |
| 60 if not os.path.exists(apk): | 64 if not os.path.exists(apk): |
| 61 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) | 65 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) |
| 62 if not os.path.exists(apk): | 66 if not os.path.exists(apk): |
| 63 parser.error('%s not found.' % apk) | 67 parser.error('%s not found.' % apk) |
| 64 | 68 |
| 65 devices = device_utils.DeviceUtils.HealthyDevices() | 69 devices = device_utils.DeviceUtils.HealthyDevices() |
| 66 | 70 |
| 71 if args.split: | |
| 72 apk_without_extension = apk[:-len('.apk')] | |
| 73 density_splits = glob.glob(apk_without_extension + '-density-*.apk') | |
|
jbudorick
2015/06/25 00:36:53
This is too automagical. agrieve provided an examp
mikecase (-- gone --)
2015/06/26 18:59:33
Changed it so that users pass in the globs that ma
| |
| 74 abi_splits = glob.glob(apk_without_extension + '-abi-*.apk') | |
| 75 language_splits = glob.glob(apk_without_extension + '-lang-*.apk') | |
| 76 | |
| 67 if args.device: | 77 if args.device: |
| 68 devices = [d for d in devices if d == args.device] | 78 devices = [d for d in devices if d == args.device] |
| 69 if not devices: | 79 if not devices: |
| 70 raise device_errors.DeviceUnreachableError(args.device) | 80 raise device_errors.DeviceUnreachableError(args.device) |
| 71 elif not devices: | 81 elif not devices: |
| 72 raise device_errors.NoDevicesError() | 82 raise device_errors.NoDevicesError() |
| 73 | 83 |
| 74 def blacklisting_install(device): | 84 def blacklisting_install(device): |
| 75 try: | 85 try: |
| 76 device.Install(apk, reinstall=args.keep_data) | 86 if args.split: |
| 87 device.InstallSplitApk( | |
| 88 apk, density_splits + abi_splits + language_splits, | |
| 89 reinstall=args.keep_data) | |
| 90 else: | |
| 91 device.Install(apk, reinstall=args.keep_data) | |
| 77 except device_errors.CommandFailedError: | 92 except device_errors.CommandFailedError: |
| 78 logging.exception('Failed to install %s', args.apk) | 93 logging.exception('Failed to install %s', args.apk) |
| 79 device_blacklist.ExtendBlacklist([str(device)]) | 94 device_blacklist.ExtendBlacklist([str(device)]) |
| 80 logging.warning('Blacklisting %s', str(device)) | 95 logging.warning('Blacklisting %s', str(device)) |
| 81 except device_errors.CommandTimeoutError: | 96 except device_errors.CommandTimeoutError: |
| 82 logging.exception('Timed out while installing %s', args.apk) | 97 logging.exception('Timed out while installing %s', args.apk) |
| 83 device_blacklist.ExtendBlacklist([str(device)]) | 98 device_blacklist.ExtendBlacklist([str(device)]) |
| 84 logging.warning('Blacklisting %s', str(device)) | 99 logging.warning('Blacklisting %s', str(device)) |
| 85 | 100 |
| 86 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) | 101 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) |
| 87 | 102 |
| 88 | 103 |
| 89 if __name__ == '__main__': | 104 if __name__ == '__main__': |
| 90 sys.exit(main()) | 105 sys.exit(main()) |
| 91 | 106 |
| OLD | NEW |