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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 parser.add_argument('--release', action='store_const', const='Release', | 52 parser.add_argument('--release', action='store_const', const='Release', |
53 dest='build_type', | 53 dest='build_type', |
54 help='If set, run test suites under out/Release. ' | 54 help='If set, run test suites under out/Release. ' |
55 'Default is env var BUILDTYPE or Debug.') | 55 'Default is env var BUILDTYPE or Debug.') |
56 parser.add_argument('-d', '--device', dest='devices', action='append', | 56 parser.add_argument('-d', '--device', dest='devices', action='append', |
57 help='Target device for apk to install on. Enter multiple' | 57 help='Target device for apk to install on. Enter multiple' |
58 ' times for multiple devices.') | 58 ' times for multiple devices.') |
59 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') | 59 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') |
60 parser.add_argument('-v', '--verbose', action='count', | 60 parser.add_argument('-v', '--verbose', action='count', |
61 help='Enable verbose logging.') | 61 help='Enable verbose logging.') |
| 62 parser.add_argument('--downgrade', action='store_true', |
| 63 help='If set, allows downgrading of apk.') |
62 | 64 |
63 args = parser.parse_args() | 65 args = parser.parse_args() |
64 | 66 |
65 run_tests_helper.SetLogLevel(args.verbose) | 67 run_tests_helper.SetLogLevel(args.verbose) |
66 constants.SetBuildType(args.build_type) | 68 constants.SetBuildType(args.build_type) |
67 | 69 |
68 devil_chromium.Initialize(output_directory=constants.GetOutDirectory()) | 70 devil_chromium.Initialize(output_directory=constants.GetOutDirectory()) |
69 | 71 |
70 apk = args.apk_path or args.apk_name | 72 apk = args.apk_path or args.apk_name |
71 if not apk.endswith('.apk'): | 73 if not apk.endswith('.apk'): |
(...skipping 24 matching lines...) Expand all Loading... |
96 if args.devices: | 98 if args.devices: |
97 devices = [d for d in devices if d in args.devices] | 99 devices = [d for d in devices if d in args.devices] |
98 if not devices: | 100 if not devices: |
99 raise device_errors.DeviceUnreachableError(args.devices) | 101 raise device_errors.DeviceUnreachableError(args.devices) |
100 elif not devices: | 102 elif not devices: |
101 raise device_errors.NoDevicesError() | 103 raise device_errors.NoDevicesError() |
102 | 104 |
103 def blacklisting_install(device): | 105 def blacklisting_install(device): |
104 try: | 106 try: |
105 if args.splits: | 107 if args.splits: |
106 device.InstallSplitApk(apk, splits, reinstall=args.keep_data) | 108 device.InstallSplitApk(apk, splits, reinstall=args.keep_data, |
| 109 allow_downgrade=args.downgrade) |
107 else: | 110 else: |
108 device.Install(apk, reinstall=args.keep_data) | 111 device.Install(apk, reinstall=args.keep_data, |
| 112 allow_downgrade=args.downgrade) |
109 except device_errors.CommandFailedError: | 113 except device_errors.CommandFailedError: |
110 logging.exception('Failed to install %s', args.apk_name) | 114 logging.exception('Failed to install %s', args.apk_name) |
111 if blacklist: | 115 if blacklist: |
112 blacklist.Extend([str(device)], reason='install_failure') | 116 blacklist.Extend([str(device)], reason='install_failure') |
113 logging.warning('Blacklisting %s', str(device)) | 117 logging.warning('Blacklisting %s', str(device)) |
114 except device_errors.CommandTimeoutError: | 118 except device_errors.CommandTimeoutError: |
115 logging.exception('Timed out while installing %s', args.apk_name) | 119 logging.exception('Timed out while installing %s', args.apk_name) |
116 if blacklist: | 120 if blacklist: |
117 blacklist.Extend([str(device)], reason='install_timeout') | 121 blacklist.Extend([str(device)], reason='install_timeout') |
118 logging.warning('Blacklisting %s', str(device)) | 122 logging.warning('Blacklisting %s', str(device)) |
119 | 123 |
120 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) | 124 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) |
121 | 125 |
122 | 126 |
123 if __name__ == '__main__': | 127 if __name__ == '__main__': |
124 sys.exit(main()) | 128 sys.exit(main()) |
125 | 129 |
OLD | NEW |