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

Unified Diff: appengine/third_party/python-adb/adb/common.py

Issue 2618043002: swarming: Roll py-adb to 75477ebf4fb8b906707f35e5fb385a9203256bef (Closed)
Patch Set: Created 3 years, 11 months 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 side-by-side diff with in-line comments
Download patch
Index: appengine/third_party/python-adb/adb/common.py
diff --git a/appengine/third_party/python-adb/adb/common.py b/appengine/third_party/python-adb/adb/common.py
index a7b2d9f6124d05060f98dd6d910777b247d60872..ae33f606112c45596926ddcefdf8b258eed77a4c 100644
--- a/appengine/third_party/python-adb/adb/common.py
+++ b/appengine/third_party/python-adb/adb/common.py
@@ -340,7 +340,7 @@ class UsbHandle(Handle):
DeviceNotFoundError: Raised if the device is not available.
"""
try:
- return next(cls.FindDevices(
+ return next(cls.FindDevicesSafe(
setting_matcher, device_matcher=device_matcher, **kwargs))
except StopIteration:
raise usb_exceptions.DeviceNotFoundError(
@@ -373,21 +373,33 @@ class UsbHandle(Handle):
yield handle
@classmethod
- def FindDevicesSafe(cls, *args, **kwargs):
- """Safe version of FindDevicesSafe.
+ def FindDevicesSafe(cls, setting_matcher, device_matcher=None,
+ usb_info='', timeout_ms=None):
+ """Safe version of FindDevices.
- Use manual iterator handling instead of "for handle in generator" to catch
- USB exception explicitly.
+ Like FindDevices, but catch USB exceptions as devices are iterated through.
+
+ Yields:
+ Unopened UsbHandle instances.
"""
- generator = cls.FindDevices(*args, **kwargs)
- while True:
- try:
- handle = generator.next()
- except usb1.USBErrorOther as e:
- logging.error(
- 'Failed to open USB device, is user in group plugdev? %s', e)
- continue
- yield handle
+ ctx = usb1.USBContext()
+ try:
+ for device in ctx.getDeviceList(skip_on_error=True):
+ setting = setting_matcher(device)
+ if setting is None:
+ continue
+
+ try:
+ handle = cls(device, setting, usb_info=usb_info,
+ timeout_ms=timeout_ms)
+ if device_matcher is None or device_matcher(handle):
+ yield handle
+ except (usb1.USBErrorOther, usb1.USBErrorNoDevice) as e:
+ logging.error(
+ 'Failed to open USB device, is user in group plugdev? %s', e)
+ continue
+ except usb1.USBError as e:
+ logging.error('Failed to get device list: %s', e)
class TcpHandle(Handle):
« no previous file with comments | « appengine/third_party/python-adb/README.swarming ('k') | appengine/third_party/python-adb/adb/contrib/high.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698