| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 | 6 |
| 7 """Produce health statistics for all attached Android devices.""" | 7 """Produce health statistics for all attached Android devices.""" |
| 8 | 8 |
| 9 | 9 |
| 10 import json | 10 import json |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 except Exception: | 59 except Exception: |
| 60 return -1 | 60 return -1 |
| 61 # Normalize the temperature, assuming it's 9 < t < 100 degrees C. | 61 # Normalize the temperature, assuming it's 9 < t < 100 degrees C. |
| 62 while temp > 100.0: | 62 while temp > 100.0: |
| 63 temp /= 10 | 63 temp /= 10 |
| 64 return temp | 64 return temp |
| 65 | 65 |
| 66 | 66 |
| 67 def get_device_stats(serial): | 67 def get_device_stats(serial): |
| 68 """Obtain and return a dictionary of device statistics.""" | 68 """Obtain and return a dictionary of device statistics.""" |
| 69 return { | 69 return get_device_model(serial), { |
| 70 'battery': get_battery_stats(serial), | 70 'battery': get_battery_stats(serial), |
| 71 'model': get_device_model(serial), | |
| 72 'temperature': get_temperature(serial), | 71 'temperature': get_temperature(serial), |
| 73 } | 72 } |
| 74 | 73 |
| 75 | 74 |
| 76 def get_all_device_stats(): | 75 def get_all_device_stats(): |
| 77 """Obtain and return statistics for all attached devices.""" | 76 """Obtain and return statistics for all attached devices.""" |
| 78 devices = get_devices() | 77 devices = get_devices() |
| 79 stats = {} | 78 stats = {} |
| 80 for device in devices: | 79 for serial in devices: |
| 81 stats[device] = get_device_stats(device) | 80 model, device_stats = get_device_stats(serial) |
| 81 if not stats.get(model): |
| 82 stats[model] = {} |
| 83 stats[model][serial] = device_stats |
| 82 return stats | 84 return stats |
| 83 | 85 |
| 84 | 86 |
| 85 if __name__ == '__main__': | 87 if __name__ == '__main__': |
| 86 print json.dumps(get_all_device_stats(), sort_keys=True, indent=4) | 88 print json.dumps(get_all_device_stats(), sort_keys=True, indent=4) |
| OLD | NEW |