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 logging | 10 import logging |
(...skipping 12 matching lines...) Expand all Loading... | |
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('--apk-split', | |
jbudorick
2015/06/24 19:00:39
Using this as-is looks like this:
./build/andro
mikecase (-- gone --)
2015/06/24 19:16:19
Almost. Using this as is looks like this...
./bui
| |
34 dest='apk_splits', | |
35 action='append', | |
36 help='An apk split. Can be specified multiple times. ' | |
37 'Used for installing a split apk.') | |
33 parser.add_argument('--keep_data', | 38 parser.add_argument('--keep_data', |
34 action='store_true', | 39 action='store_true', |
35 default=False, | 40 default=False, |
36 help='Keep the package data when installing ' | 41 help='Keep the package data when installing ' |
37 'the application.') | 42 'the application.') |
38 parser.add_argument('--debug', action='store_const', const='Debug', | 43 parser.add_argument('--debug', action='store_const', const='Debug', |
39 dest='build_type', | 44 dest='build_type', |
40 default=os.environ.get('BUILDTYPE', 'Debug'), | 45 default=os.environ.get('BUILDTYPE', 'Debug'), |
41 help='If set, run test suites under out/Debug. ' | 46 help='If set, run test suites under out/Debug. ' |
42 'Default is env var BUILDTYPE or Debug') | 47 'Default is env var BUILDTYPE or Debug') |
43 parser.add_argument('--release', action='store_const', const='Release', | 48 parser.add_argument('--release', action='store_const', const='Release', |
44 dest='build_type', | 49 dest='build_type', |
45 help='If set, run test suites under out/Release. ' | 50 help='If set, run test suites under out/Release. ' |
46 'Default is env var BUILDTYPE or Debug.') | 51 'Default is env var BUILDTYPE or Debug.') |
47 parser.add_argument('-d', '--device', dest='device', | 52 parser.add_argument('-d', '--device', dest='device', |
48 help='Target device for apk to install on.') | 53 help='Target device for apk to install on.') |
49 parser.add_argument('-v', '--verbose', action='count', | 54 parser.add_argument('-v', '--verbose', action='count', |
50 help='Enable verbose logging.') | 55 help='Enable verbose logging.') |
51 | 56 |
52 args = parser.parse_args() | 57 args = parser.parse_args() |
53 | 58 |
54 run_tests_helper.SetLogLevel(args.verbose) | 59 run_tests_helper.SetLogLevel(args.verbose) |
55 constants.SetBuildType(args.build_type) | 60 constants.SetBuildType(args.build_type) |
56 | 61 |
62 def resolve_apk_path(apk): | |
63 if not apk.endswith('.apk'): | |
64 apk += '.apk' | |
65 if not os.path.exists(apk): | |
66 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) | |
67 if not os.path.exists(apk): | |
68 parser.error('%s not found.' % apk) | |
69 return apk | |
70 | |
57 apk = args.apk_path or args.apk_name | 71 apk = args.apk_path or args.apk_name |
58 if not apk.endswith('.apk'): | 72 apk = resolve_apk_path(apk) |
59 apk += '.apk' | 73 |
60 if not os.path.exists(apk): | 74 if args.apk_splits: |
61 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) | 75 for i, apk_split in enumerate(args.apk_splits): |
62 if not os.path.exists(apk): | 76 args.apk_splits[i] = resolve_apk_path(apk_split) |
63 parser.error('%s not found.' % apk) | |
64 | 77 |
65 devices = device_utils.DeviceUtils.HealthyDevices() | 78 devices = device_utils.DeviceUtils.HealthyDevices() |
66 | 79 |
67 if args.device: | 80 if args.device: |
68 devices = [d for d in devices if d == args.device] | 81 devices = [d for d in devices if d == args.device] |
69 if not devices: | 82 if not devices: |
70 raise device_errors.DeviceUnreachableError(args.device) | 83 raise device_errors.DeviceUnreachableError(args.device) |
71 elif not devices: | 84 elif not devices: |
72 raise device_errors.NoDevicesError() | 85 raise device_errors.NoDevicesError() |
73 | 86 |
74 def blacklisting_install(device): | 87 def blacklisting_install(device): |
75 try: | 88 try: |
76 device.Install(apk, reinstall=args.keep_data) | 89 if args.apk_splits: |
90 device.InstallSplitApk(apk, args.apk_splits, reinstall=args.keep_data) | |
91 else: | |
92 device.Install(apk, reinstall=args.keep_data) | |
77 except device_errors.CommandFailedError: | 93 except device_errors.CommandFailedError: |
78 logging.exception('Failed to install %s', args.apk) | 94 logging.exception('Failed to install %s', args.apk) |
79 device_blacklist.ExtendBlacklist([str(device)]) | 95 device_blacklist.ExtendBlacklist([str(device)]) |
80 logging.warning('Blacklisting %s', str(device)) | 96 logging.warning('Blacklisting %s', str(device)) |
81 except device_errors.CommandTimeoutError: | 97 except device_errors.CommandTimeoutError: |
82 logging.exception('Timed out while installing %s', args.apk) | 98 logging.exception('Timed out while installing %s', args.apk) |
83 device_blacklist.ExtendBlacklist([str(device)]) | 99 device_blacklist.ExtendBlacklist([str(device)]) |
84 logging.warning('Blacklisting %s', str(device)) | 100 logging.warning('Blacklisting %s', str(device)) |
85 | 101 |
86 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) | 102 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) |
87 | 103 |
88 | 104 |
89 if __name__ == '__main__': | 105 if __name__ == '__main__': |
90 sys.exit(main()) | 106 sys.exit(main()) |
91 | 107 |
OLD | NEW |