| 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 | 8 |
| 9 import optparse | 9 import optparse |
| 10 import os | 10 import os |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 def CheckForMissingDevices(options, adb_online_devs): | 52 def CheckForMissingDevices(options, adb_online_devs): |
| 53 """Uses file of previous online devices to detect broken phones. | 53 """Uses file of previous online devices to detect broken phones. |
| 54 | 54 |
| 55 Args: | 55 Args: |
| 56 options: out_dir parameter of options argument is used as the base | 56 options: out_dir parameter of options argument is used as the base |
| 57 directory to load and update the cache file. | 57 directory to load and update the cache file. |
| 58 adb_online_devs: A list of serial numbers of the currently visible | 58 adb_online_devs: A list of serial numbers of the currently visible |
| 59 and online attached devices. | 59 and online attached devices. |
| 60 """ | 60 """ |
| 61 | 61 out_dir = os.path.abspath(options.out_dir) |
| 62 last_devices_path = os.path.abspath(os.path.join(options.out_dir, | 62 last_devices_path = os.path.join(out_dir, '.last_devices') |
| 63 '.last_devices')) | |
| 64 last_devices = [] | 63 last_devices = [] |
| 65 try: | 64 try: |
| 66 with open(last_devices_path) as f: | 65 with open(last_devices_path) as f: |
| 67 last_devices = f.read().splitlines() | 66 last_devices = f.read().splitlines() |
| 68 except IOError: | 67 except IOError: |
| 69 # Ignore error, file might not exist | 68 # Ignore error, file might not exist |
| 70 pass | 69 pass |
| 71 | 70 |
| 72 missing_devs = list(set(last_devices) - set(adb_online_devs)) | 71 missing_devs = list(set(last_devices) - set(adb_online_devs)) |
| 73 if missing_devs: | 72 if missing_devs: |
| 74 buildbot_report.PrintWarning() | 73 buildbot_report.PrintWarning() |
| 75 buildbot_report.PrintSummaryText( | 74 buildbot_report.PrintSummaryText( |
| 76 '%d devices not detected.' % len(missing_devs)) | 75 '%d devices not detected.' % len(missing_devs)) |
| 77 print 'Current online devices: %s' % adb_online_devs | 76 print 'Current online devices: %s' % adb_online_devs |
| 78 print '%s are no longer visible. Were they removed?\n' % missing_devs | 77 print '%s are no longer visible. Were they removed?\n' % missing_devs |
| 79 print 'SHERIFF: See go/chrome_device_monitor' | 78 print 'SHERIFF: See go/chrome_device_monitor' |
| 80 print 'Cache file: %s\n\n' % last_devices_path | 79 print 'Cache file: %s\n\n' % last_devices_path |
| 81 print 'adb devices' | 80 print 'adb devices' |
| 82 print GetCmdOutput(['adb', 'devices']) | 81 print GetCmdOutput(['adb', 'devices']) |
| 83 else: | 82 else: |
| 84 new_devs = set(adb_online_devs) - set(last_devices) | 83 new_devs = set(adb_online_devs) - set(last_devices) |
| 85 if new_devs and os.path.exists(last_devices_path): | 84 if new_devs and os.path.exists(last_devices_path): |
| 86 buildbot_report.PrintWarning() | 85 buildbot_report.PrintWarning() |
| 87 buildbot_report.PrintSummaryText( | 86 buildbot_report.PrintSummaryText( |
| 88 '%d new devices detected' % len(new_devs)) | 87 '%d new devices detected' % len(new_devs)) |
| 89 print ('New devices detected %s. And now back to your ' | 88 print ('New devices detected %s. And now back to your ' |
| 90 'regularly scheduled program.' % list(new_devs)) | 89 'regularly scheduled program.' % list(new_devs)) |
| 91 | 90 |
| 92 # Write devices currently visible plus devices previously seen. | 91 if not os.path.exists(out_dir): |
| 92 os.makedirs(out_dir) |
| 93 with open(last_devices_path, 'w') as f: | 93 with open(last_devices_path, 'w') as f: |
| 94 # Write devices currently visible plus devices previously seen. |
| 94 f.write('\n'.join(set(adb_online_devs + last_devices))) | 95 f.write('\n'.join(set(adb_online_devs + last_devices))) |
| 95 | 96 |
| 96 | 97 |
| 97 def main(): | 98 def main(): |
| 98 parser = optparse.OptionParser() | 99 parser = optparse.OptionParser() |
| 99 parser.add_option('', '--out-dir', | 100 parser.add_option('', '--out-dir', |
| 100 help='Directory where the device path is stored', | 101 help='Directory where the device path is stored', |
| 101 default=os.path.join(os.path.dirname(__file__), '..', | 102 default=os.path.join(os.path.dirname(__file__), '..', |
| 102 '..', 'out')) | 103 '..', 'out')) |
| 103 | 104 |
| 104 options, args = parser.parse_args() | 105 options, args = parser.parse_args() |
| 105 if args: | 106 if args: |
| 106 parser.error('Unknown options %s' % args) | 107 parser.error('Unknown options %s' % args) |
| 107 buildbot_report.PrintNamedStep('Device Status Check') | 108 buildbot_report.PrintNamedStep('Device Status Check') |
| 108 devices = GetAttachedDevices() | 109 devices = GetAttachedDevices() |
| 109 types, builds, reports = [], [], [] | 110 types, builds, reports = [], [], [] |
| 110 if devices: | 111 if devices: |
| 111 types, builds, reports = zip(*[DeviceInfo(dev) for dev in devices]) | 112 types, builds, reports = zip(*[DeviceInfo(dev) for dev in devices]) |
| 112 | 113 |
| 113 unique_types = list(set(types)) | 114 unique_types = list(set(types)) |
| 114 unique_builds = list(set(builds)) | 115 unique_builds = list(set(builds)) |
| 115 | 116 |
| 116 buildbot_report.PrintMsg('Online devices: %d. Device types %s, builds %s' | 117 buildbot_report.PrintMsg('Online devices: %d. Device types %s, builds %s' |
| 117 % (len(devices), unique_types, unique_builds)) | 118 % (len(devices), unique_types, unique_builds)) |
| 118 print '\n'.join(reports) | 119 print '\n'.join(reports) |
| 119 CheckForMissingDevices(options, devices) | 120 CheckForMissingDevices(options, devices) |
| 120 | 121 |
| 121 if __name__ == '__main__': | 122 if __name__ == '__main__': |
| 122 sys.exit(main()) | 123 sys.exit(main()) |
| OLD | NEW |