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 import logging | 8 import logging |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
(...skipping 27 matching lines...) Expand all Loading... | |
38 device_type = device_adb.GetBuildProduct() | 38 device_type = device_adb.GetBuildProduct() |
39 device_build = device_adb.GetBuildId() | 39 device_build = device_adb.GetBuildId() |
40 device_build_type = device_adb.GetBuildType() | 40 device_build_type = device_adb.GetBuildType() |
41 device_product_name = device_adb.GetProductName() | 41 device_product_name = device_adb.GetProductName() |
42 | 42 |
43 setup_wizard_disabled = device_adb.GetSetupWizardStatus() == 'DISABLED' | 43 setup_wizard_disabled = device_adb.GetSetupWizardStatus() == 'DISABLED' |
44 battery = device_adb.GetBatteryInfo() | 44 battery = device_adb.GetBatteryInfo() |
45 install_output = GetCmdOutput( | 45 install_output = GetCmdOutput( |
46 ['%s/build/android/adb_install_apk.py' % constants.DIR_SOURCE_ROOT, '--apk', | 46 ['%s/build/android/adb_install_apk.py' % constants.DIR_SOURCE_ROOT, '--apk', |
47 '%s/build/android/CheckInstallApk-debug.apk' % constants.DIR_SOURCE_ROOT]) | 47 '%s/build/android/CheckInstallApk-debug.apk' % constants.DIR_SOURCE_ROOT]) |
48 install_speed_found = re.findall('(\d+) KB/s', install_output) | 48 |
49 if install_speed_found: | 49 def _GetData(re_expression, line, lambda_function=lambda x:x): |
tomhudson
2013/07/25 11:25:20
lambdas? Ooh, fancy!
| |
50 install_speed = int(install_speed_found[0]) | 50 if not line: |
51 else: | 51 return 'Unknown' |
52 install_speed = 'Unknown' | 52 found = re.findall(re_expression, line) |
53 if 'Error' in battery: | 53 if found and len(found): |
54 ac_power = 'Unknown' | 54 return lambda_function(found[0]) |
55 battery_level = 'Unknown' | 55 return 'Unknown' |
56 battery_temp = 'Unknown' | 56 |
57 else: | 57 install_speed = _GetData('(\d+) KB/s', install_output) |
58 ac_power = re.findall('AC powered: (\w+)', battery)[0] | 58 ac_power = _GetData('AC powered: (\w+)', battery) |
59 battery_level = int(re.findall('level: (\d+)', battery)[0]) | 59 battery_level = _GetData('level: (\d+)', battery) |
60 battery_temp = float(re.findall('temperature: (\d+)', battery)[0]) / 10 | 60 battery_temp = _GetData('temperature: (\d+)', battery, |
61 sub_info = device_adb.GetSubscriberInfo() | 61 lambda x: float(x) / 10.0) |
62 imei_slice = '' | 62 imei_slice = _GetData('Device ID = (\d+)', |
63 device_id = re.findall('Device ID = (\d+)', sub_info) | 63 device_adb.GetSubscriberInfo(), |
64 if device_id and len(device_id): | 64 lambda x: x[-6:]) |
65 imei_slice = device_id[0][-6:] | |
66 report = ['Device %s (%s)' % (serial, device_type), | 65 report = ['Device %s (%s)' % (serial, device_type), |
67 ' Build: %s (%s)' % | 66 ' Build: %s (%s)' % |
68 (device_build, device_adb.GetBuildFingerprint()), | 67 (device_build, device_adb.GetBuildFingerprint()), |
69 ' Battery: %s%%' % battery_level, | 68 ' Battery: %s%%' % battery_level, |
70 ' Battery temp: %s' % battery_temp, | 69 ' Battery temp: %s' % battery_temp, |
71 ' IMEI slice: %s' % imei_slice, | 70 ' IMEI slice: %s' % imei_slice, |
72 ' Wifi IP: %s' % device_adb.GetWifiIP(), | 71 ' Wifi IP: %s' % device_adb.GetWifiIP(), |
73 ' Install Speed: %s KB/s' % install_speed, | 72 ' Install Speed: %s KB/s' % install_speed, |
74 ''] | 73 ''] |
75 | 74 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 # devices with critically low battery or install speed. Remove those devices | 240 # devices with critically low battery or install speed. Remove those devices |
242 # from testing, allowing build to continue with good devices. | 241 # from testing, allowing build to continue with good devices. |
243 return 1 | 242 return 1 |
244 | 243 |
245 if not devices: | 244 if not devices: |
246 return 1 | 245 return 1 |
247 | 246 |
248 | 247 |
249 if __name__ == '__main__': | 248 if __name__ == '__main__': |
250 sys.exit(main()) | 249 sys.exit(main()) |
OLD | NEW |