Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: build/android/buildbot/bb_device_status_check.py

Issue 727543003: [Android] Fix new pylint errors in build/android/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/avd.py ('k') | build/android/buildbot/bb_device_steps.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 device_build = device_adb.GetProp('ro.build.id') 50 device_build = device_adb.GetProp('ro.build.id')
51 device_build_type = device_adb.GetProp('ro.build.type') 51 device_build_type = device_adb.GetProp('ro.build.type')
52 device_product_name = device_adb.GetProp('ro.product.name') 52 device_product_name = device_adb.GetProp('ro.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('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.GetProp('ro.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'),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 from_address = 'chrome-bot@chromium.org' 145 from_address = 'chrome-bot@chromium.org'
146 to_addresses = ['chrome-labs-tech-ticket@google.com', 146 to_addresses = ['chrome-labs-tech-ticket@google.com',
147 'chrome-android-device-alert@google.com'] 147 'chrome-android-device-alert@google.com']
148 cc_addresses = ['chrome-android-device-alert@google.com'] 148 cc_addresses = ['chrome-android-device-alert@google.com']
149 subject = 'Devices offline on %s, %s, %s' % ( 149 subject = 'Devices offline on %s, %s, %s' % (
150 os.environ.get('BUILDBOT_SLAVENAME'), 150 os.environ.get('BUILDBOT_SLAVENAME'),
151 os.environ.get('BUILDBOT_BUILDERNAME'), 151 os.environ.get('BUILDBOT_BUILDERNAME'),
152 os.environ.get('BUILDBOT_BUILDNUMBER')) 152 os.environ.get('BUILDBOT_BUILDNUMBER'))
153 msg = ('Please reboot the following devices:\n%s' % 153 msg = ('Please reboot the following devices:\n%s' %
154 '\n'.join(map(str,new_missing_devs))) 154 '\n'.join(map(str, new_missing_devs)))
155 SendEmail(from_address, to_addresses, cc_addresses, subject, msg) 155 SendEmail(from_address, to_addresses, cc_addresses, subject, msg)
156 156
157 all_known_devices = list(set(adb_online_devs) | set(last_devices)) 157 all_known_devices = list(set(adb_online_devs) | set(last_devices))
158 device_list.WritePersistentDeviceList(last_devices_path, all_known_devices) 158 device_list.WritePersistentDeviceList(last_devices_path, all_known_devices)
159 device_list.WritePersistentDeviceList(last_missing_devices_path, missing_devs) 159 device_list.WritePersistentDeviceList(last_missing_devices_path, missing_devs)
160 160
161 if not all_known_devices: 161 if not all_known_devices:
162 # This can happen if for some reason the .last_devices file is not 162 # This can happen if for some reason the .last_devices file is not
163 # present or if it was empty. 163 # present or if it was empty.
164 return ['No online devices. Have any devices been plugged in?'] 164 return ['No online devices. Have any devices been plugged in?']
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 def RestartUsb(): 210 def RestartUsb():
211 if not os.path.isfile('/usr/bin/restart_usb'): 211 if not os.path.isfile('/usr/bin/restart_usb'):
212 print ('ERROR: Could not restart usb. /usr/bin/restart_usb not installed ' 212 print ('ERROR: Could not restart usb. /usr/bin/restart_usb not installed '
213 'on host (see BUG=305769).') 213 'on host (see BUG=305769).')
214 return False 214 return False
215 215
216 lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE) 216 lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE)
217 lsusb_output, _ = lsusb_proc.communicate() 217 lsusb_output, _ = lsusb_proc.communicate()
218 if lsusb_proc.returncode: 218 if lsusb_proc.returncode:
219 print ('Error: Could not get list of USB ports (i.e. lsusb).') 219 print 'Error: Could not get list of USB ports (i.e. lsusb).'
220 return lsusb_proc.returncode 220 return lsusb_proc.returncode
221 221
222 usb_devices = [re.findall('Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0] 222 usb_devices = [re.findall(r'Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0]
223 for lsusb_line in lsusb_output.strip().split('\n')] 223 for lsusb_line in lsusb_output.strip().split('\n')]
224 224
225 all_restarted = True 225 all_restarted = True
226 # Walk USB devices from leaves up (i.e reverse sorted) restarting the 226 # Walk USB devices from leaves up (i.e reverse sorted) restarting the
227 # connection. If a parent node (e.g. usb hub) is restarted before the 227 # connection. If a parent node (e.g. usb hub) is restarted before the
228 # devices connected to it, the (bus, dev) for the hub can change, making the 228 # devices connected to it, the (bus, dev) for the hub can change, making the
229 # output we have wrong. This way we restart the devices before the hub. 229 # output we have wrong. This way we restart the devices before the hub.
230 for (bus, dev) in reversed(sorted(usb_devices)): 230 for (bus, dev) in reversed(sorted(usb_devices)):
231 # Can not restart root usb connections 231 # Can not restart root usb connections
232 if dev != '001': 232 if dev != '001':
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
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())
OLDNEW
« no previous file with comments | « build/android/avd.py ('k') | build/android/buildbot/bb_device_steps.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698