commit c1d14b9677af4c58b47514901e4b8ae74b11d64b
parent 192e8959339919ea29305573369ff40ce1e7eda2
Author: SomberNight <somber.night@protonmail.com>
Date: Thu, 8 Mar 2018 02:45:39 +0100
trezor: try and allow transports to fail independently
related: #4060
Diffstat:
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/plugins/trezor/trezor.py b/plugins/trezor/trezor.py
@@ -127,8 +127,28 @@ class TrezorPlugin(HW_PluginBase):
self.device_manager().register_enumerate_func(self.enumerate)
def enumerate(self):
- from trezorlib.device import TrezorDevice
- return [Device(d.get_path(), -1, d.get_path(), 'TREZOR', 0) for d in TrezorDevice.enumerate()]
+ try:
+ from trezorlib.transport import all_transports
+ except ImportError:
+ # compat for trezorlib < 0.9.2
+ def all_transports():
+ from trezorlib.transport_bridge import BridgeTransport
+ from trezorlib.transport_hid import HidTransport
+ from trezorlib.transport_udp import UdpTransport
+ from trezorlib.transport_webusb import WebUsbTransport
+ return (BridgeTransport, HidTransport, UdpTransport, WebUsbTransport)
+
+ devices = []
+ for transport in all_transports():
+ try:
+ new_devices = transport.enumerate()
+ except BaseException as e:
+ self.print_error('enumerate failed for {}. error {}'
+ .format(transport.__name__, str(e)))
+ else:
+ devices.extend(new_devices)
+
+ return [Device(d.get_path(), -1, d.get_path(), 'TREZOR', 0) for d in devices]
def create_client(self, device, handler):
from trezorlib.device import TrezorDevice