From fe897a786e1fc7c3d5e4225a1fff070a22316a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 29 Dec 2019 15:38:51 +0100 Subject: [PATCH] Attempt at having more useful errors for plugin setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp_omemo/__init__.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index b2d0d52..448ed95 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -32,14 +32,17 @@ from .stanza import Bundle, Devices, Device, Encrypted, Key, PreKeyPublic log = logging.getLogger(__name__) -HAS_OMEMO = True +HAS_OMEMO = False +HAS_OMEMO_BACKEND = False try: import omemo.exceptions from omemo import SessionManager, ExtendedPublicBundle, DefaultOTPKPolicy from omemo.util import generateDeviceID from omemo.implementations import JSONFileStorage from omemo.backends import Backend + HAS_OMEMO = True from omemo_backend_signal import BACKEND as SignalBackend + HAS_OMEMO_BACKEND = True except (ImportError,): class Backend: pass @@ -50,8 +53,6 @@ except (ImportError,): class SignalBackend: pass - HAS_OMEMO = False - TRUE_VALUES = {True, 'true', '1'} PUBLISH_OPTIONS_NODE = 'http://jabber.org/protocol/pubsub#publish-options' PUBSUB_ERRORS = 'http://jabber.org/protocol/pubsub#errors' @@ -186,15 +187,21 @@ class XEP_0384(BasePlugin): 'omemo_backend': SignalBackend, } - backend_loaded = HAS_OMEMO + backend_loaded = HAS_OMEMO and HAS_OMEMO_BACKEND # OMEMO Bundles used for encryption bundles = {} # type: Dict[str, Dict[int, ExtendedPublicBundle]] def plugin_init(self) -> None: if not self.backend_loaded: - log.info("xep_0384 cannot be loaded as the backend omemo library " - "is not available") + log_str = ("xep_0384 cannot be loaded as the backend omemo library " + "is not available. ") + if not HAS_OMEMO_BACKEND: + log_str += ("Make sure you have a python OMEMO backend " + "(python-omemo-backend-signal) installed") + else: + log_str += "Make sure you have the python OMEMO library installed." + log.error(log_str) raise PluginCouldNotLoad if not self.data_dir: