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 json | 8 import json |
9 import logging | 9 import logging |
10 import optparse | 10 import optparse |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 Args: | 40 Args: |
41 serial: The serial of the attached device to construct info about. | 41 serial: The serial of the attached device to construct info about. |
42 | 42 |
43 Returns: | 43 Returns: |
44 Tuple of device type, build id, report as a string, error messages, and | 44 Tuple of device type, build id, report as a string, error messages, and |
45 boolean indicating whether or not device can be used for testing. | 45 boolean indicating whether or not device can be used for testing. |
46 """ | 46 """ |
47 | 47 |
48 device_adb = device_utils.DeviceUtils(serial) | 48 device_adb = device_utils.DeviceUtils(serial) |
49 device_type = device_adb.GetProp('ro.build.product') | 49 device_type = device_adb.build_product |
50 device_build = device_adb.GetProp('ro.build.id') | 50 device_build = device_adb.build_id |
51 device_build_type = device_adb.GetProp('ro.build.type') | 51 device_build_type = device_adb.build_type |
52 device_product_name = device_adb.GetProp('ro.product.name') | 52 device_product_name = device_adb.product_name |
53 | 53 |
54 try: | 54 try: |
55 battery_info = device_adb.old_interface.GetBatteryInfo() | 55 battery_info = device_adb.old_interface.GetBatteryInfo() |
56 except Exception as e: | 56 except Exception as e: |
57 battery_info = {} | 57 battery_info = {} |
58 logging.error('Unable to obtain battery info for %s, %s', serial, e) | 58 logging.error('Unable to obtain battery info for %s, %s', serial, e) |
59 | 59 |
60 def _GetData(re_expression, line, lambda_function=lambda x: x): | 60 def _GetData(re_expression, line, lambda_function=lambda x: x): |
61 if not line: | 61 if not line: |
62 return 'Unknown' | 62 return 'Unknown' |
63 found = re.findall(re_expression, line) | 63 found = re.findall(re_expression, line) |
64 if found and len(found): | 64 if found and len(found): |
65 return lambda_function(found[0]) | 65 return lambda_function(found[0]) |
66 return 'Unknown' | 66 return 'Unknown' |
67 | 67 |
68 battery_level = int(battery_info.get('level', 100)) | 68 battery_level = int(battery_info.get('level', 100)) |
69 imei_slice = _GetData(r'Device ID = (\d+)', | 69 imei_slice = _GetData(r'Device ID = (\d+)', |
70 device_adb.old_interface.GetSubscriberInfo(), | 70 device_adb.old_interface.GetSubscriberInfo(), |
71 lambda x: x[-6:]) | 71 lambda x: x[-6:]) |
72 report = ['Device %s (%s)' % (serial, device_type), | 72 report = ['Device %s (%s)' % (serial, device_type), |
73 ' Build: %s (%s)' % | 73 ' Build: %s (%s)' % |
74 (device_build, device_adb.GetProp('ro.build.fingerprint')), | 74 (device_build, device_adb.build_fingerprint), |
75 ' Current Battery Service state: ', | 75 ' Current Battery Service state: ', |
76 '\n'.join([' %s: %s' % (k, v) | 76 '\n'.join([' %s: %s' % (k, v) |
77 for k, v in battery_info.iteritems()]), | 77 for k, v in battery_info.iteritems()]), |
78 ' IMEI slice: %s' % imei_slice, | 78 ' IMEI slice: %s' % imei_slice, |
79 ' Wifi IP: %s' % device_adb.GetProp('dhcp.wlan0.ipaddress'), | 79 ' Wifi IP: %s' % device_adb.GetProp('dhcp.wlan0.ipaddress'), |
80 ''] | 80 ''] |
81 | 81 |
82 errors = [] | 82 errors = [] |
83 dev_good = True | 83 dev_good = True |
84 if battery_level < 15: | 84 if battery_level < 15: |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 379 |
380 if num_failed_devs == len(devices): | 380 if num_failed_devs == len(devices): |
381 return 2 | 381 return 2 |
382 | 382 |
383 if not devices: | 383 if not devices: |
384 return 1 | 384 return 1 |
385 | 385 |
386 | 386 |
387 if __name__ == '__main__': | 387 if __name__ == '__main__': |
388 sys.exit(main()) | 388 sys.exit(main()) |
OLD | NEW |