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