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 argparse | 13 import argparse |
14 import glob | |
jbudorick
2015/03/04 00:20:46
nit: remove this
| |
14 import logging | 15 import logging |
15 import os | 16 import os |
16 import posixpath | 17 import posixpath |
17 import re | 18 import re |
18 import subprocess | 19 import subprocess |
19 import sys | 20 import sys |
20 import time | 21 import time |
21 | 22 |
22 from pylib import android_commands | 23 from pylib import android_commands |
23 from pylib import constants | 24 from pylib import constants |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 device: the device to wipe | 139 device: the device to wipe |
139 """ | 140 """ |
140 device_authorized = device.FileExists(constants.ADB_KEYS_FILE) | 141 device_authorized = device.FileExists(constants.ADB_KEYS_FILE) |
141 if device_authorized: | 142 if device_authorized: |
142 adb_keys = device.ReadFile(constants.ADB_KEYS_FILE, | 143 adb_keys = device.ReadFile(constants.ADB_KEYS_FILE, |
143 as_root=True).splitlines() | 144 as_root=True).splitlines() |
144 device.RunShellCommand('wipe data', as_root=True) | 145 device.RunShellCommand('wipe data', as_root=True) |
145 if device_authorized: | 146 if device_authorized: |
146 adb_keys_set = set(adb_keys) | 147 adb_keys_set = set(adb_keys) |
147 for adb_key_file in options.adb_key_files or []: | 148 for adb_key_file in options.adb_key_files or []: |
148 with open(adb_key_file, 'r') as f: | 149 try: |
149 adb_public_keys = f.readlines() | 150 with open(adb_key_file, 'r') as f: |
150 adb_keys_set.update(adb_public_keys) | 151 adb_public_keys = f.readlines() |
152 adb_keys_set.update(adb_public_keys) | |
153 except IOError: | |
154 logging.warning('Unable to find adb keys file %s.' % adb_key_file) | |
151 WriteAdbKeysFile(device, '\n'.join(adb_keys_set)) | 155 WriteAdbKeysFile(device, '\n'.join(adb_keys_set)) |
152 | 156 |
153 | 157 |
154 def WipeDeviceIfPossible(device, timeout, options): | 158 def WipeDeviceIfPossible(device, timeout, options): |
155 try: | 159 try: |
156 device.EnableRoot() | 160 device.EnableRoot() |
157 WipeDeviceData(device, options) | 161 WipeDeviceData(device, options) |
158 device.Reboot(True, timeout=timeout, retries=0) | 162 device.Reboot(True, timeout=timeout, retries=0) |
159 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): | 163 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): |
160 pass | 164 pass |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 parser.add_argument('--adb-key-files', type=str, nargs='+', | 296 parser.add_argument('--adb-key-files', type=str, nargs='+', |
293 help='list of adb keys to push to device') | 297 help='list of adb keys to push to device') |
294 args = parser.parse_args() | 298 args = parser.parse_args() |
295 constants.SetBuildType(args.target) | 299 constants.SetBuildType(args.target) |
296 | 300 |
297 return ProvisionDevices(args) | 301 return ProvisionDevices(args) |
298 | 302 |
299 | 303 |
300 if __name__ == '__main__': | 304 if __name__ == '__main__': |
301 sys.exit(main()) | 305 sys.exit(main()) |
OLD | NEW |