From db8079b699d306805e3349fbea5feb6751a3e8c1 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Mon, 25 Sep 2023 10:17:56 +0200 Subject: [PATCH] fix typo in setup.py handle if apprise cannot be imported --- borgmatic/hooks/apprise.py | 24 ++++++++++++++---------- setup.py | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/borgmatic/hooks/apprise.py b/borgmatic/hooks/apprise.py index b70532b3..555600bb 100644 --- a/borgmatic/hooks/apprise.py +++ b/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: diff --git a/setup.py b/setup.py index b4757d48..8902f76f 100644 --- a/setup.py +++ b/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,