| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 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 """A class to keep track of devices across builds and report state.""" | 7 """A class to keep track of devices across builds and report state.""" |
| 8 | 8 |
| 9 import argparse | 9 import argparse |
| 10 import json | 10 import json |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 battery = battery_utils.BatteryUtils(device) | 61 battery = battery_utils.BatteryUtils(device) |
| 62 battery_info = battery.GetBatteryInfo(timeout=5) | 62 battery_info = battery.GetBatteryInfo(timeout=5) |
| 63 battery_level = int(battery_info.get('level', 100)) | 63 battery_level = int(battery_info.get('level', 100)) |
| 64 | 64 |
| 65 if battery_level < 15: | 65 if battery_level < 15: |
| 66 logging.error('Critically low battery level (%d)', battery_level) | 66 logging.error('Critically low battery level (%d)', battery_level) |
| 67 battery = battery_utils.BatteryUtils(device) | 67 battery = battery_utils.BatteryUtils(device) |
| 68 if not battery.GetCharging(): | 68 if not battery.GetCharging(): |
| 69 battery.SetCharging(True) | 69 battery.SetCharging(True) |
| 70 if blacklist: | 70 if blacklist: |
| 71 blacklist.Extend([device.GetDeviceSerial()]) | 71 blacklist.Extend([device.adb.GetDeviceSerial()]) |
| 72 | 72 |
| 73 except device_errors.CommandFailedError: | 73 except device_errors.CommandFailedError: |
| 74 logging.exception('Failed to get battery information for %s', | 74 logging.exception('Failed to get battery information for %s', |
| 75 str(device)) | 75 str(device)) |
| 76 | 76 |
| 77 return battery_info | 77 return battery_info |
| 78 | 78 |
| 79 | 79 |
| 80 def _IMEISlice(device): | 80 def _IMEISlice(device): |
| 81 imei_slice = '' | 81 imei_slice = '' |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 device_errors.CommandFailedError): | 248 device_errors.CommandFailedError): |
| 249 logging.exception('Failure while waiting for %s. ' | 249 logging.exception('Failure while waiting for %s. ' |
| 250 'Attempting to recover.', str(device)) | 250 'Attempting to recover.', str(device)) |
| 251 | 251 |
| 252 try: | 252 try: |
| 253 device.Reboot() | 253 device.Reboot() |
| 254 device.WaitUntilFullyBooted() | 254 device.WaitUntilFullyBooted() |
| 255 except device_errors.CommandFailedError: | 255 except device_errors.CommandFailedError: |
| 256 logging.exception('Failure while waiting for %s.', str(device)) | 256 logging.exception('Failure while waiting for %s.', str(device)) |
| 257 if blacklist: | 257 if blacklist: |
| 258 blacklist.Extend([str(device)]) | 258 blacklist.Extend([device.adb.GetDeviceSerial()]) |
| 259 except device_errors.CommandTimeoutError: | 259 except device_errors.CommandTimeoutError: |
| 260 logging.exception('Timed out while waiting for %s. ', str(device)) | 260 logging.exception('Timed out while waiting for %s. ', str(device)) |
| 261 if blacklist: | 261 if blacklist: |
| 262 blacklist.Extend([str(device)]) | 262 blacklist.Extend([device.adb.GetDeviceSerial()]) |
| 263 | 263 |
| 264 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_recovery) | 264 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_recovery) |
| 265 | 265 |
| 266 | 266 |
| 267 def main(): | 267 def main(): |
| 268 parser = argparse.ArgumentParser() | 268 parser = argparse.ArgumentParser() |
| 269 parser.add_argument('--out-dir', | 269 parser.add_argument('--out-dir', |
| 270 help='Directory where the device path is stored', | 270 help='Directory where the device path is stored', |
| 271 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) | 271 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out')) |
| 272 parser.add_argument('--restart-usb', action='store_true', | 272 parser.add_argument('--restart-usb', action='store_true', |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 live_devices = [status['serial'] for status in statuses | 359 live_devices = [status['serial'] for status in statuses |
| 360 if (status['adb_status'] == 'device' | 360 if (status['adb_status'] == 'device' |
| 361 and status['serial'] not in blacklist.Read())] | 361 and status['serial'] not in blacklist.Read())] |
| 362 | 362 |
| 363 # If all devices failed, or if there are no devices, it's an infra error. | 363 # If all devices failed, or if there are no devices, it's an infra error. |
| 364 return 0 if live_devices else constants.INFRA_EXIT_CODE | 364 return 0 if live_devices else constants.INFRA_EXIT_CODE |
| 365 | 365 |
| 366 | 366 |
| 367 if __name__ == '__main__': | 367 if __name__ == '__main__': |
| 368 sys.exit(main()) | 368 sys.exit(main()) |
| OLD | NEW |