Browse Source

hw: check_libraries_available now gets version of incompatible libs

previously we would return early and the user would
just see "missing libraries"
3.3.3.1
SomberNight 6 years ago
parent
commit
8c3920a0db
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 11
      electrum/plugins/coldcard/coldcard.py
  2. 29
      electrum/plugins/hw_wallet/plugin.py
  3. 14
      electrum/plugins/trezor/trezor.py

11
electrum/plugins/coldcard/coldcard.py

@ -17,6 +17,7 @@ from electrum.util import print_error, bfh, bh2u, versiontuple, UserFacingExcept
from electrum.base_wizard import ScriptTypeNotSupported
from ..hw_wallet import HW_PluginBase
from ..hw_wallet.plugin import LibraryFoundButUnusable
try:
import hid
@ -610,7 +611,7 @@ class ColdcardPlugin(HW_PluginBase):
def __init__(self, parent, config, name):
HW_PluginBase.__init__(self, parent, config, name)
self.libraries_available = self.check_libraries_available() and requirements_ok
self.libraries_available = self.check_libraries_available()
if not self.libraries_available:
return
@ -620,9 +621,13 @@ class ColdcardPlugin(HW_PluginBase):
def get_library_version(self):
import ckcc
try:
return ckcc.__version__
version = ckcc.__version__
except AttributeError:
return 'unknown'
version = 'unknown'
if requirements_ok:
return version
else:
raise LibraryFoundButUnusable(library_version=version)
def detect_simulator(self):
# if there is a simulator running on this machine,

29
electrum/plugins/hw_wallet/plugin.py

@ -86,6 +86,7 @@ class HW_PluginBase(BasePlugin):
Returns 'unknown' if library is found but cannot determine version.
Raises 'ImportError' if library is not found.
Raises 'LibraryFoundButUnusable' if found but there was some problem (includes version num).
"""
raise NotImplementedError()
@ -94,23 +95,22 @@ class HW_PluginBase(BasePlugin):
return ".".join(str(i) for i in t)
try:
# this might raise ImportError or LibraryFoundButUnusable
library_version = self.get_library_version()
# if no exception so far, we might still raise LibraryFoundButUnusable
if (library_version == 'unknown'
or versiontuple(library_version) < self.minimum_library
or hasattr(self, "maximum_library") and versiontuple(library_version) >= self.maximum_library):
raise LibraryFoundButUnusable(library_version=library_version)
except ImportError:
return False
if library_version == 'unknown' or \
versiontuple(library_version) < self.minimum_library:
self.libraries_available_message = (
_("Library version for '{}' is too old.").format(self.name)
+ '\nInstalled: {}, Needed: {}'
.format(library_version, version_str(self.minimum_library)))
self.print_stderr(self.libraries_available_message)
return False
elif hasattr(self, "maximum_library") and \
versiontuple(library_version) >= self.maximum_library:
except LibraryFoundButUnusable as e:
library_version = e.library_version
max_version_str = version_str(self.maximum_library) if hasattr(self, "maximum_library") else "inf"
self.libraries_available_message = (
_("Library version for '{}' is incompatible.").format(self.name)
+ '\nInstalled: {}, Needed: less than {}'
.format(library_version, version_str(self.maximum_library)))
+ '\nInstalled: {}, Needed: {} <= x < {}'
.format(library_version, version_str(self.minimum_library), max_version_str))
self.print_stderr(self.libraries_available_message)
return False
@ -155,3 +155,8 @@ def only_hook_if_libraries_available(func):
if not self.libraries_available: return None
return func(self, *args, **kwargs)
return wrapper
class LibraryFoundButUnusable(Exception):
def __init__(self, library_version='unknown'):
self.library_version = library_version

14
electrum/plugins/trezor/trezor.py

@ -12,7 +12,8 @@ from electrum.keystore import Hardware_KeyStore, is_xpubkey, parse_xpubkey
from electrum.base_wizard import ScriptTypeNotSupported, HWD_SETUP_NEW_WALLET
from ..hw_wallet import HW_PluginBase
from ..hw_wallet.plugin import is_any_tx_output_on_change_branch, trezor_validate_op_return_output_and_get_data
from ..hw_wallet.plugin import (is_any_tx_output_on_change_branch, trezor_validate_op_return_output_and_get_data,
LibraryFoundButUnusable)
try:
import trezorlib
@ -112,12 +113,15 @@ class TrezorPlugin(HW_PluginBase):
self.device_manager().register_enumerate_func(self.enumerate)
def get_library_version(self):
if not TREZORLIB:
raise ImportError
import trezorlib
try:
return trezorlib.__version__
version = trezorlib.__version__
except Exception:
return 'unknown'
version = 'unknown'
if TREZORLIB:
return version
else:
raise LibraryFoundButUnusable(library_version=version)
def enumerate(self):
devices = trezorlib.transport.enumerate_devices()

Loading…
Cancel
Save