Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Side by Side Diff: build/android/adb_install_apk.py

Issue 1895163002: 🐠 Use the new DeviceUtils.HealthyDevices(device_arg=) in a few scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/adb_command_line.py ('k') | build/android/adb_reverse_forwarder.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 parser.add_argument('--debug', action='store_const', const='Debug', 47 parser.add_argument('--debug', action='store_const', const='Debug',
48 dest='build_type', 48 dest='build_type',
49 default=os.environ.get('BUILDTYPE', 'Debug'), 49 default=os.environ.get('BUILDTYPE', 'Debug'),
50 help='If set, run test suites under out/Debug. ' 50 help='If set, run test suites under out/Debug. '
51 'Default is env var BUILDTYPE or Debug') 51 'Default is env var BUILDTYPE or Debug')
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 default=[],
57 help='Target device for apk to install on. Enter multiple' 58 help='Target device for apk to install on. Enter multiple'
58 ' times for multiple devices.') 59 ' times for multiple devices.')
59 parser.add_argument('--adb-path', 60 parser.add_argument('--adb-path',
60 help='Absolute path to the adb binary to use.') 61 help='Absolute path to the adb binary to use.')
61 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') 62 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
62 parser.add_argument('-v', '--verbose', action='count', 63 parser.add_argument('-v', '--verbose', action='count',
63 help='Enable verbose logging.') 64 help='Enable verbose logging.')
64 parser.add_argument('--downgrade', action='store_true', 65 parser.add_argument('--downgrade', action='store_true',
65 help='If set, allows downgrading of apk.') 66 help='If set, allows downgrading of apk.')
66 parser.add_argument('--timeout', type=int, 67 parser.add_argument('--timeout', type=int,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 logging.warning('No apks matched for %s.', split_glob) 103 logging.warning('No apks matched for %s.', split_glob)
103 for f in apks: 104 for f in apks:
104 helper = apk_helper.ApkHelper(f) 105 helper = apk_helper.ApkHelper(f)
105 if (helper.GetPackageName() == base_apk_package 106 if (helper.GetPackageName() == base_apk_package
106 and helper.GetSplitName()): 107 and helper.GetSplitName()):
107 splits.append(f) 108 splits.append(f)
108 109
109 blacklist = (device_blacklist.Blacklist(args.blacklist_file) 110 blacklist = (device_blacklist.Blacklist(args.blacklist_file)
110 if args.blacklist_file 111 if args.blacklist_file
111 else None) 112 else None)
112 devices = device_utils.DeviceUtils.HealthyDevices(blacklist) 113 devices = device_utils.DeviceUtils.HealthyDevices(blacklist=blacklist,
113 114 device_arg=args.devices)
114 if args.devices:
115 devices = [d for d in devices if d in args.devices]
116 if not devices:
117 raise device_errors.DeviceUnreachableError(args.devices)
118 elif not devices:
119 raise device_errors.NoDevicesError()
120 115
121 def blacklisting_install(device): 116 def blacklisting_install(device):
122 try: 117 try:
123 if args.splits: 118 if args.splits:
124 device.InstallSplitApk(apk, splits, reinstall=args.keep_data, 119 device.InstallSplitApk(apk, splits, reinstall=args.keep_data,
125 allow_downgrade=args.downgrade) 120 allow_downgrade=args.downgrade)
126 else: 121 else:
127 device.Install(apk, reinstall=args.keep_data, 122 device.Install(apk, reinstall=args.keep_data,
128 allow_downgrade=args.downgrade, 123 allow_downgrade=args.downgrade,
129 timeout=args.timeout) 124 timeout=args.timeout)
130 except device_errors.CommandFailedError: 125 except device_errors.CommandFailedError:
131 logging.exception('Failed to install %s', args.apk_name) 126 logging.exception('Failed to install %s', args.apk_name)
132 if blacklist: 127 if blacklist:
133 blacklist.Extend([str(device)], reason='install_failure') 128 blacklist.Extend([str(device)], reason='install_failure')
134 logging.warning('Blacklisting %s', str(device)) 129 logging.warning('Blacklisting %s', str(device))
135 except device_errors.CommandTimeoutError: 130 except device_errors.CommandTimeoutError:
136 logging.exception('Timed out while installing %s', args.apk_name) 131 logging.exception('Timed out while installing %s', args.apk_name)
137 if blacklist: 132 if blacklist:
138 blacklist.Extend([str(device)], reason='install_timeout') 133 blacklist.Extend([str(device)], reason='install_timeout')
139 logging.warning('Blacklisting %s', str(device)) 134 logging.warning('Blacklisting %s', str(device))
140 135
141 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) 136 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install)
142 137
143 138
144 if __name__ == '__main__': 139 if __name__ == '__main__':
145 sys.exit(main()) 140 sys.exit(main())
146 141
OLDNEW
« no previous file with comments | « build/android/adb_command_line.py ('k') | build/android/adb_reverse_forwarder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698