| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 if not os.path.exists(out_dir): | 100 if not os.path.exists(out_dir): |
| 101 os.makedirs(out_dir) | 101 os.makedirs(out_dir) |
| 102 with open(path, 'w') as f: | 102 with open(path, 'w') as f: |
| 103 # Write devices currently visible plus devices previously seen. | 103 # Write devices currently visible plus devices previously seen. |
| 104 f.write('\n'.join(set(device_list))) | 104 f.write('\n'.join(set(device_list))) |
| 105 | 105 |
| 106 last_devices_path = os.path.join(out_dir, '.last_devices') | 106 last_devices_path = os.path.join(out_dir, '.last_devices') |
| 107 last_devices = ReadDeviceList('.last_devices') | 107 last_devices = ReadDeviceList('.last_devices') |
| 108 missing_devs = list(set(last_devices) - set(adb_online_devs)) | 108 missing_devs = list(set(last_devices) - set(adb_online_devs)) |
| 109 | 109 |
| 110 WriteDeviceList('.last_devices', (adb_online_devs + last_devices)) | 110 all_known_devices = list(set(adb_online_devs) | set(last_devices)) |
| 111 WriteDeviceList('.last_devices', all_known_devices) |
| 111 WriteDeviceList('.last_missing', missing_devs) | 112 WriteDeviceList('.last_missing', missing_devs) |
| 112 | 113 |
| 114 if not all_known_devices: |
| 115 # This can happen if for some reason the .last_devices file is not |
| 116 # present or if it was empty. |
| 117 return ['No online devices. Have any devices been plugged in?'] |
| 113 if missing_devs: | 118 if missing_devs: |
| 114 devices_missing_msg = '%d devices not detected.' % len(missing_devs) | 119 devices_missing_msg = '%d devices not detected.' % len(missing_devs) |
| 115 buildbot_report.PrintSummaryText(devices_missing_msg) | 120 buildbot_report.PrintSummaryText(devices_missing_msg) |
| 116 | 121 |
| 117 # TODO(navabi): Debug by printing both output from GetCmdOutput and | 122 # TODO(navabi): Debug by printing both output from GetCmdOutput and |
| 118 # GetAttachedDevices to compare results. | 123 # GetAttachedDevices to compare results. |
| 119 return ['Current online devices: %s' % adb_online_devs, | 124 return ['Current online devices: %s' % adb_online_devs, |
| 120 '%s are no longer visible. Were they removed?\n' % missing_devs, | 125 '%s are no longer visible. Were they removed?\n' % missing_devs, |
| 121 'SHERIFF: See go/chrome_device_monitor', | 126 'SHERIFF: See go/chrome_device_monitor', |
| 122 'Cache file: %s\n\n' % last_devices_path, | 127 'Cache file: %s\n\n' % last_devices_path, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 msg = '\n'.join(err_msg) | 188 msg = '\n'.join(err_msg) |
| 184 print msg | 189 print msg |
| 185 SendDeviceStatusAlert(msg) | 190 SendDeviceStatusAlert(msg) |
| 186 | 191 |
| 187 if not devices: | 192 if not devices: |
| 188 return 1 | 193 return 1 |
| 189 | 194 |
| 190 | 195 |
| 191 if __name__ == '__main__': | 196 if __name__ == '__main__': |
| 192 sys.exit(main()) | 197 sys.exit(main()) |
| OLD | NEW |