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 glob |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 'the application.') | 44 'the application.') |
45 parser.add_argument('--debug', action='store_const', const='Debug', | 45 parser.add_argument('--debug', action='store_const', const='Debug', |
46 dest='build_type', | 46 dest='build_type', |
47 default=os.environ.get('BUILDTYPE', 'Debug'), | 47 default=os.environ.get('BUILDTYPE', 'Debug'), |
48 help='If set, run test suites under out/Debug. ' | 48 help='If set, run test suites under out/Debug. ' |
49 'Default is env var BUILDTYPE or Debug') | 49 'Default is env var BUILDTYPE or Debug') |
50 parser.add_argument('--release', action='store_const', const='Release', | 50 parser.add_argument('--release', action='store_const', const='Release', |
51 dest='build_type', | 51 dest='build_type', |
52 help='If set, run test suites under out/Release. ' | 52 help='If set, run test suites under out/Release. ' |
53 'Default is env var BUILDTYPE or Debug.') | 53 'Default is env var BUILDTYPE or Debug.') |
54 parser.add_argument('-d', '--device', dest='device', | 54 parser.add_argument('-d', '--device', dest='devices', action='append', |
55 help='Target device for apk to install on.') | 55 help='Target device for apk to install on. Enter multiple' |
| 56 ' times for multiple devices.') |
56 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') | 57 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') |
57 parser.add_argument('-v', '--verbose', action='count', | 58 parser.add_argument('-v', '--verbose', action='count', |
58 help='Enable verbose logging.') | 59 help='Enable verbose logging.') |
59 | 60 |
60 args = parser.parse_args() | 61 args = parser.parse_args() |
61 | 62 |
62 run_tests_helper.SetLogLevel(args.verbose) | 63 run_tests_helper.SetLogLevel(args.verbose) |
63 constants.SetBuildType(args.build_type) | 64 constants.SetBuildType(args.build_type) |
64 | 65 |
65 apk = args.apk_path or args.apk_name | 66 apk = args.apk_path or args.apk_name |
(...skipping 15 matching lines...) Expand all Loading... |
81 helper = apk_helper.ApkHelper(f) | 82 helper = apk_helper.ApkHelper(f) |
82 if (helper.GetPackageName() == base_apk_package | 83 if (helper.GetPackageName() == base_apk_package |
83 and helper.GetSplitName()): | 84 and helper.GetSplitName()): |
84 splits.append(f) | 85 splits.append(f) |
85 | 86 |
86 blacklist = (device_blacklist.Blacklist(args.blacklist_file) | 87 blacklist = (device_blacklist.Blacklist(args.blacklist_file) |
87 if args.blacklist_file | 88 if args.blacklist_file |
88 else None) | 89 else None) |
89 devices = device_utils.DeviceUtils.HealthyDevices(blacklist) | 90 devices = device_utils.DeviceUtils.HealthyDevices(blacklist) |
90 | 91 |
91 if args.device: | 92 if args.devices: |
92 devices = [d for d in devices if d == args.device] | 93 devices = [d for d in devices if d in args.devices] |
93 if not devices: | 94 if not devices: |
94 raise device_errors.DeviceUnreachableError(args.device) | 95 raise device_errors.DeviceUnreachableError(args.devices) |
95 elif not devices: | 96 elif not devices: |
96 raise device_errors.NoDevicesError() | 97 raise device_errors.NoDevicesError() |
97 | 98 |
98 def blacklisting_install(device): | 99 def blacklisting_install(device): |
99 try: | 100 try: |
100 if args.splits: | 101 if args.splits: |
101 device.InstallSplitApk(apk, splits, reinstall=args.keep_data) | 102 device.InstallSplitApk(apk, splits, reinstall=args.keep_data) |
102 else: | 103 else: |
103 device.Install(apk, reinstall=args.keep_data) | 104 device.Install(apk, reinstall=args.keep_data) |
104 except device_errors.CommandFailedError: | 105 except device_errors.CommandFailedError: |
105 logging.exception('Failed to install %s', args.apk_name) | 106 logging.exception('Failed to install %s', args.apk_name) |
106 if blacklist: | 107 if blacklist: |
107 blacklist.Extend([str(device)], reason='install_failure') | 108 blacklist.Extend([str(device)], reason='install_failure') |
108 logging.warning('Blacklisting %s', str(device)) | 109 logging.warning('Blacklisting %s', str(device)) |
109 except device_errors.CommandTimeoutError: | 110 except device_errors.CommandTimeoutError: |
110 logging.exception('Timed out while installing %s', args.apk_name) | 111 logging.exception('Timed out while installing %s', args.apk_name) |
111 if blacklist: | 112 if blacklist: |
112 blacklist.Extend([str(device)], reason='install_timeout') | 113 blacklist.Extend([str(device)], reason='install_timeout') |
113 logging.warning('Blacklisting %s', str(device)) | 114 logging.warning('Blacklisting %s', str(device)) |
114 | 115 |
115 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) | 116 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) |
116 | 117 |
117 | 118 |
118 if __name__ == '__main__': | 119 if __name__ == '__main__': |
119 sys.exit(main()) | 120 sys.exit(main()) |
120 | 121 |
OLD | NEW |