瀏覽代碼

fix typo in setup.py
handle if apprise cannot be imported

Pim Kunis 1 年之前
父節點
當前提交
db8079b699
共有 2 個文件被更改,包括 15 次插入11 次删除
  1. 14 10
      borgmatic/hooks/apprise.py
  2. 1 1
      setup.py

+ 14 - 10
borgmatic/hooks/apprise.py

@@ -1,17 +1,7 @@
 import logging
 
-import apprise
-from apprise import NotifyType, NotifyFormat
-
 logger = logging.getLogger(__name__)
 
-state_to_notify_type = {
-    'start': NotifyType.INFO,
-    'finish': NotifyType.SUCCESS,
-    'fail': NotifyType.FAILURE,
-    'log': NotifyType.INFO
-}
-
 
 def initialize_monitor(
     ping_url, config, config_filename, monitoring_log_level, dry_run
@@ -27,6 +17,20 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
     Ping the configured Apprise service URLs. Use the given configuration filename in any log
     entries. If this is a dry run, then don't actually ping anything.
     '''
+    try:
+        import apprise
+        from apprise import NotifyType, NotifyFormat
+    except ImportError:
+        logger.warning('Unable to import Apprise in monitoring hook')
+        return
+
+    state_to_notify_type = {
+        'start': NotifyType.INFO,
+        'finish': NotifyType.SUCCESS,
+        'fail': NotifyType.FAILURE,
+        'log': NotifyType.INFO
+    }
+
     run_states = hook_config.get('states', ['fail'])
 
     if state.name.lower() not in run_states:

+ 1 - 1
setup.py

@@ -36,7 +36,7 @@ setup(
         'ruamel.yaml>0.15.0,<0.18.0',
         'setuptools'
     ),
-    extra_require={
+    extras_require={
         "Apprise": ["apprise"]
     },
     include_package_data=True,