OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2013 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 """Provisions Android devices with settings required for bots. | 7 """Provisions Android devices with settings required for bots. |
8 | 8 |
9 Usage: | 9 Usage: |
10 ./provision_devices.py [-d <device serial number>] | 10 ./provision_devices.py [-d <device serial number>] |
11 """ | 11 """ |
12 | 12 |
13 import logging | 13 import logging |
14 import optparse | 14 import optparse |
15 import os | 15 import os |
16 import re | 16 import re |
17 import subprocess | 17 import subprocess |
18 import sys | 18 import sys |
19 import time | 19 import time |
20 | 20 |
21 from pylib import android_commands | 21 from pylib import android_commands |
22 from pylib import constants | 22 from pylib import constants |
23 from pylib import device_settings | 23 from pylib import device_settings |
24 from pylib.device import device_blacklist | 24 from pylib.device import device_blacklist |
25 from pylib.device import device_errors | 25 from pylib.device import device_errors |
26 from pylib.device import device_utils | 26 from pylib.device import device_utils |
| 27 from pylib.utils import run_tests_helper |
27 | 28 |
28 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, | 29 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, |
29 'third_party', 'android_testrunner')) | 30 'third_party', 'android_testrunner')) |
30 import errors | 31 import errors |
31 | 32 |
32 def KillHostHeartbeat(): | 33 def KillHostHeartbeat(): |
33 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) | 34 ps = subprocess.Popen(['ps', 'aux'], stdout = subprocess.PIPE) |
34 stdout, _ = ps.communicate() | 35 stdout, _ = ps.communicate() |
35 matches = re.findall('\\n.*host_heartbeat.*', stdout) | 36 matches = re.findall('\\n.*host_heartbeat.*', stdout) |
36 for match in matches: | 37 for match in matches: |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 249 |
249 # If there are no good devices | 250 # If there are no good devices |
250 if not devices: | 251 if not devices: |
251 raise device_errors.NoDevicesError | 252 raise device_errors.NoDevicesError |
252 | 253 |
253 if options.auto_reconnect: | 254 if options.auto_reconnect: |
254 PushAndLaunchAdbReboot(devices, options.target) | 255 PushAndLaunchAdbReboot(devices, options.target) |
255 | 256 |
256 | 257 |
257 def main(argv): | 258 def main(argv): |
258 logging.basicConfig(level=logging.INFO) | 259 custom_handler = logging.StreamHandler(sys.stdout) |
| 260 custom_handler.setFormatter(run_tests_helper.CustomFormatter()) |
| 261 logging.getLogger().addHandler(custom_handler) |
| 262 logging.getLogger().setLevel(logging.INFO) |
259 | 263 |
260 parser = optparse.OptionParser() | 264 parser = optparse.OptionParser() |
261 parser.add_option('--skip-wipe', action='store_true', default=False, | 265 parser.add_option('--skip-wipe', action='store_true', default=False, |
262 help="Don't wipe device data during provisioning.") | 266 help="Don't wipe device data during provisioning.") |
263 parser.add_option('--disable-location', action='store_true', default=False, | 267 parser.add_option('--disable-location', action='store_true', default=False, |
264 help="Disallow Google location services on devices.") | 268 help="Disallow Google location services on devices.") |
265 parser.add_option('-d', '--device', | 269 parser.add_option('-d', '--device', |
266 help='The serial number of the device to be provisioned') | 270 help='The serial number of the device to be provisioned') |
267 parser.add_option('-t', '--target', default='Debug', help='The build target') | 271 parser.add_option('-t', '--target', default='Debug', help='The build target') |
268 parser.add_option( | 272 parser.add_option( |
269 '-r', '--auto-reconnect', action='store_true', | 273 '-r', '--auto-reconnect', action='store_true', |
270 help='Push binary which will reboot the device on adb disconnections.') | 274 help='Push binary which will reboot the device on adb disconnections.') |
271 options, args = parser.parse_args(argv[1:]) | 275 options, args = parser.parse_args(argv[1:]) |
272 constants.SetBuildType(options.target) | 276 constants.SetBuildType(options.target) |
273 | 277 |
274 if args: | 278 if args: |
275 print >> sys.stderr, 'Unused args %s' % args | 279 print >> sys.stderr, 'Unused args %s' % args |
276 return 1 | 280 return 1 |
277 | 281 |
278 ProvisionDevices(options) | 282 ProvisionDevices(options) |
279 | 283 |
280 | 284 |
281 if __name__ == '__main__': | 285 if __name__ == '__main__': |
282 sys.exit(main(sys.argv)) | 286 sys.exit(main(sys.argv)) |
OLD | NEW |