mirror of
https://github.com/caronc/apprise.git
synced 2025-08-12 17:47:19 +02:00
Microsoft Power Automate / Workflows Support (#1172)
Co-authored-by: Toby Coleman <toby-coleman@users.noreply.github.com>
This commit is contained in:
@ -30,6 +30,7 @@ from itertools import chain
|
||||
from importlib import import_module, reload
|
||||
from apprise import NotificationManager
|
||||
from apprise import AttachmentManager
|
||||
from apprise import ConfigurationManager
|
||||
import sys
|
||||
import re
|
||||
|
||||
@ -39,6 +40,9 @@ N_MGR = NotificationManager()
|
||||
# Grant access to our Attachment Manager Singleton
|
||||
A_MGR = AttachmentManager()
|
||||
|
||||
# Grant access to our Configuration Manager Singleton
|
||||
C_MGR = ConfigurationManager()
|
||||
|
||||
# For filtering our result when scanning a module
|
||||
# Identify any items below we should match on that we can freely
|
||||
# directly copy around between our modules. This should only
|
||||
@ -71,6 +75,21 @@ def reload_plugin(name):
|
||||
reload(sys.modules[module_pyname])
|
||||
new_notify_mod = import_module(module_pyname)
|
||||
|
||||
A_MGR.unload_modules()
|
||||
|
||||
reload(sys.modules['apprise.apprise_config'])
|
||||
reload(sys.modules['apprise.config.base'])
|
||||
new_apprise_configuration_mod = import_module('apprise.apprise_config')
|
||||
new_apprise_config_base_mod = import_module('apprise.config.base')
|
||||
reload(sys.modules['apprise.manager_config'])
|
||||
|
||||
C_MGR.unload_modules()
|
||||
|
||||
module_pyname = '{}.{}'.format(N_MGR.module_name_prefix, name)
|
||||
if module_pyname in sys.modules:
|
||||
reload(sys.modules[module_pyname])
|
||||
new_notify_mod = import_module(module_pyname)
|
||||
|
||||
# Detect our class object
|
||||
class_matches = {}
|
||||
for class_name in [obj for obj in dir(new_notify_mod)
|
||||
@ -117,15 +136,18 @@ def reload_plugin(name):
|
||||
for class_name, class_plugin in class_matches.items():
|
||||
if hasattr(test_mod, class_name):
|
||||
setattr(test_mod, class_name, class_plugin)
|
||||
#
|
||||
# This section below reloads our attachment classes
|
||||
#
|
||||
|
||||
#
|
||||
# Detect our Apprise Modules (include helpers)
|
||||
#
|
||||
apprise_modules = \
|
||||
sorted([k for k in sys.modules.keys()
|
||||
if re.match(r'^(apprise|helpers)(\.|.+)$', k)], reverse=True)
|
||||
|
||||
#
|
||||
# This section below reloads our attachment classes
|
||||
#
|
||||
|
||||
for entry in A_MGR:
|
||||
reload(sys.modules[entry['path']])
|
||||
for module_pyname in chain(apprise_modules, tests):
|
||||
@ -173,3 +195,55 @@ def reload_plugin(name):
|
||||
for class_name, class_plugin in class_matches.items():
|
||||
if hasattr(apprise_mod, class_name):
|
||||
setattr(apprise_mod, class_name, class_plugin)
|
||||
|
||||
#
|
||||
# This section below reloads our configuration classes
|
||||
#
|
||||
|
||||
for entry in C_MGR:
|
||||
reload(sys.modules[entry['path']])
|
||||
for module_pyname in chain(apprise_modules, tests):
|
||||
detect = re.compile(
|
||||
r'^(?P<name>(AppriseConfig|ConfigBase|' +
|
||||
entry['path'].split('.')[-1] + r'))$')
|
||||
|
||||
possible_matches = \
|
||||
[m for m in dir(sys.modules[module_pyname]) if detect.match(m)]
|
||||
if not possible_matches:
|
||||
continue
|
||||
|
||||
apprise_mod = import_module(module_pyname)
|
||||
# Fix reference to new plugin class in given module.
|
||||
# Needed for updating the module-level import reference
|
||||
# like `from apprise.<etc> import ConfigABCDE`.
|
||||
#
|
||||
# We reload NotifyABCDE and place it back in its spot
|
||||
# new_attach = import_module(entry['path'])
|
||||
for name in possible_matches:
|
||||
if name == 'AppriseConfig':
|
||||
setattr(
|
||||
apprise_mod, name,
|
||||
getattr(new_apprise_configuration_mod, name))
|
||||
|
||||
elif name == 'ConfigBase':
|
||||
setattr(
|
||||
apprise_mod, name,
|
||||
getattr(new_apprise_config_base_mod, name))
|
||||
|
||||
else:
|
||||
module_pyname = '{}.{}'.format(
|
||||
A_MGR.module_name_prefix, name)
|
||||
new_config_mod = import_module(module_pyname)
|
||||
|
||||
# Detect our class object
|
||||
class_matches = {}
|
||||
for class_name in [obj for obj in dir(new_config_mod)
|
||||
if module_filter_re.match(obj)]:
|
||||
|
||||
# Store our entry
|
||||
class_matches[class_name] = \
|
||||
getattr(new_config_mod, class_name)
|
||||
|
||||
for class_name, class_plugin in class_matches.items():
|
||||
if hasattr(apprise_mod, class_name):
|
||||
setattr(apprise_mod, class_name, class_plugin)
|
||||
|
Reference in New Issue
Block a user