|
|
@ -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 |
|
|
|