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 |
| 19 from pylib.utils import apk_helper |
18 from pylib.utils import run_tests_helper | 20 from pylib.utils import run_tests_helper |
19 | 21 |
20 | 22 |
21 def main(): | 23 def main(): |
22 parser = argparse.ArgumentParser() | 24 parser = argparse.ArgumentParser() |
23 | 25 |
24 apk_group = parser.add_mutually_exclusive_group(required=True) | 26 apk_group = parser.add_mutually_exclusive_group(required=True) |
25 apk_group.add_argument('--apk', dest='apk_name', | 27 apk_group.add_argument('--apk', dest='apk_name', |
26 help='DEPRECATED The name of the apk containing the' | 28 help='DEPRECATED The name of the apk containing the' |
27 ' application (with the .apk extension).') | 29 ' application (with the .apk extension).') |
28 apk_group.add_argument('apk_path', nargs='?', | 30 apk_group.add_argument('apk_path', nargs='?', |
29 help='The path to the APK to install.') | 31 help='The path to the APK to install.') |
30 | 32 |
31 # TODO(jbudorick): Remove once no clients pass --apk_package | 33 # TODO(jbudorick): Remove once no clients pass --apk_package |
32 parser.add_argument('--apk_package', help='DEPRECATED unused') | 34 parser.add_argument('--apk_package', help='DEPRECATED unused') |
| 35 parser.add_argument('--split', |
| 36 action='append', |
| 37 dest='splits', |
| 38 help='A glob matching the apk splits. ' |
| 39 'Can be specified multiple times.') |
33 parser.add_argument('--keep_data', | 40 parser.add_argument('--keep_data', |
34 action='store_true', | 41 action='store_true', |
35 default=False, | 42 default=False, |
36 help='Keep the package data when installing ' | 43 help='Keep the package data when installing ' |
37 'the application.') | 44 'the application.') |
38 parser.add_argument('--debug', action='store_const', const='Debug', | 45 parser.add_argument('--debug', action='store_const', const='Debug', |
39 dest='build_type', | 46 dest='build_type', |
40 default=os.environ.get('BUILDTYPE', 'Debug'), | 47 default=os.environ.get('BUILDTYPE', 'Debug'), |
41 help='If set, run test suites under out/Debug. ' | 48 help='If set, run test suites under out/Debug. ' |
42 'Default is env var BUILDTYPE or Debug') | 49 'Default is env var BUILDTYPE or Debug') |
(...skipping 12 matching lines...) Expand all Loading... |
55 constants.SetBuildType(args.build_type) | 62 constants.SetBuildType(args.build_type) |
56 | 63 |
57 apk = args.apk_path or args.apk_name | 64 apk = args.apk_path or args.apk_name |
58 if not apk.endswith('.apk'): | 65 if not apk.endswith('.apk'): |
59 apk += '.apk' | 66 apk += '.apk' |
60 if not os.path.exists(apk): | 67 if not os.path.exists(apk): |
61 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) | 68 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) |
62 if not os.path.exists(apk): | 69 if not os.path.exists(apk): |
63 parser.error('%s not found.' % apk) | 70 parser.error('%s not found.' % apk) |
64 | 71 |
| 72 if args.splits: |
| 73 splits = [] |
| 74 base_apk_package = apk_helper.ApkHelper(apk).GetPackageName() |
| 75 for split_glob in args.splits: |
| 76 apks = [f for f in glob.glob(split_glob) if f.endswith('.apk')] |
| 77 if not apks: |
| 78 logging.warning('No apks matched for %s.' % split_glob) |
| 79 for f in apks: |
| 80 helper = apk_helper.ApkHelper(f) |
| 81 if (helper.GetPackageName() == base_apk_package |
| 82 and helper.GetSplitName()): |
| 83 splits.append(f) |
| 84 |
65 devices = device_utils.DeviceUtils.HealthyDevices() | 85 devices = device_utils.DeviceUtils.HealthyDevices() |
66 | 86 |
67 if args.device: | 87 if args.device: |
68 devices = [d for d in devices if d == args.device] | 88 devices = [d for d in devices if d == args.device] |
69 if not devices: | 89 if not devices: |
70 raise device_errors.DeviceUnreachableError(args.device) | 90 raise device_errors.DeviceUnreachableError(args.device) |
71 elif not devices: | 91 elif not devices: |
72 raise device_errors.NoDevicesError() | 92 raise device_errors.NoDevicesError() |
73 | 93 |
74 def blacklisting_install(device): | 94 def blacklisting_install(device): |
75 try: | 95 try: |
76 device.Install(apk, reinstall=args.keep_data) | 96 if args.splits: |
| 97 device.InstallSplitApk(apk, splits, reinstall=args.keep_data) |
| 98 else: |
| 99 device.Install(apk, reinstall=args.keep_data) |
77 except device_errors.CommandFailedError: | 100 except device_errors.CommandFailedError: |
78 logging.exception('Failed to install %s', args.apk_name) | 101 logging.exception('Failed to install %s', args.apk_name) |
79 device_blacklist.ExtendBlacklist([str(device)]) | 102 device_blacklist.ExtendBlacklist([str(device)]) |
80 logging.warning('Blacklisting %s', str(device)) | 103 logging.warning('Blacklisting %s', str(device)) |
81 except device_errors.CommandTimeoutError: | 104 except device_errors.CommandTimeoutError: |
82 logging.exception('Timed out while installing %s', args.apk_name) | 105 logging.exception('Timed out while installing %s', args.apk_name) |
83 device_blacklist.ExtendBlacklist([str(device)]) | 106 device_blacklist.ExtendBlacklist([str(device)]) |
84 logging.warning('Blacklisting %s', str(device)) | 107 logging.warning('Blacklisting %s', str(device)) |
85 | 108 |
86 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) | 109 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) |
87 | 110 |
88 | 111 |
89 if __name__ == '__main__': | 112 if __name__ == '__main__': |
90 sys.exit(main()) | 113 sys.exit(main()) |
91 | 114 |
OLD | NEW |