| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging | 5 import logging |
| 6 import re | 6 import re |
| 7 | 7 |
| 8 from devil.utils import cmd_helper | 8 from devil.utils import cmd_helper |
| 9 | 9 |
| 10 _COULDNT_OPEN_ERROR_RE = re.compile(r'Couldn\'t open device.*') | 10 _COULDNT_OPEN_ERROR_RE = re.compile(r'Couldn\'t open device.*') |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 def lsusb(): | 80 def lsusb(): |
| 81 """Call lsusb and return the parsed output.""" | 81 """Call lsusb and return the parsed output.""" |
| 82 _, lsusb_list_output = cmd_helper.GetCmdStatusAndOutputWithTimeout( | 82 _, lsusb_list_output = cmd_helper.GetCmdStatusAndOutputWithTimeout( |
| 83 ['lsusb'], timeout=2) | 83 ['lsusb'], timeout=2) |
| 84 devices = [] | 84 devices = [] |
| 85 for line in lsusb_list_output.splitlines(): | 85 for line in lsusb_list_output.splitlines(): |
| 86 m = _LSUSB_BUS_DEVICE_RE.match(line) | 86 m = _LSUSB_BUS_DEVICE_RE.match(line) |
| 87 if m: | 87 if m: |
| 88 bus_num = m.group(1) | 88 bus_num = m.group(1) |
| 89 dev_num = m.group(2) | 89 dev_num = m.group(2) |
| 90 devices.append(_lsusbv_on_device(bus_num, dev_num)) | 90 try: |
| 91 devices.append(_lsusbv_on_device(bus_num, dev_num)) |
| 92 except cmd_helper.TimeoutError: |
| 93 # Will be blacklisted if it is in expected device file, but times out. |
| 94 logging.info('lsusb -v %s:%s timed out.', bus_num, dev_num) |
| 95 |
| 91 return devices | 96 return devices |
| 92 | 97 |
| 93 def get_lsusb_serial(device): | 98 def get_lsusb_serial(device): |
| 94 try: | 99 try: |
| 95 return device['Device Descriptor']['iSerial']['_desc'] | 100 return device['Device Descriptor']['iSerial']['_desc'] |
| 96 except KeyError: | 101 except KeyError: |
| 97 return None | 102 return None |
| 98 | 103 |
| 99 def get_android_devices(): | 104 def get_android_devices(): |
| 100 return [serial for serial in (get_lsusb_serial(d) for d in lsusb()) | 105 return [serial for serial in (get_lsusb_serial(d) for d in lsusb()) |
| 101 if serial] | 106 if serial] |
| OLD | NEW |