summaryrefslogtreecommitdiff
path: root/src/mailman/core/initialize.py
diff options
context:
space:
mode:
authorJ08nY2017-08-07 18:36:22 +0200
committerJ08nY2017-08-07 18:36:22 +0200
commitd107fd41f03b57f7731b60bb7ba921febc3ce3b9 (patch)
treecda2a8b12804345da87c043cfa90f6bb59bd83b3 /src/mailman/core/initialize.py
parent9421a6ad9c3d272fd16ece2c21d317ab48251dae (diff)
parent8addebbf9802e911c06f6a27b7ffff1e0f1d2e57 (diff)
downloadmailman-d107fd41f03b57f7731b60bb7ba921febc3ce3b9.tar.gz
mailman-d107fd41f03b57f7731b60bb7ba921febc3ce3b9.tar.zst
mailman-d107fd41f03b57f7731b60bb7ba921febc3ce3b9.zip
Diffstat (limited to 'src/mailman/core/initialize.py')
-rw-r--r--src/mailman/core/initialize.py50
1 files changed, 44 insertions, 6 deletions
diff --git a/src/mailman/core/initialize.py b/src/mailman/core/initialize.py
index dc67e9a68..830bd9b84 100644
--- a/src/mailman/core/initialize.py
+++ b/src/mailman/core/initialize.py
@@ -26,9 +26,12 @@ by the command line arguments.
import os
import sys
+import warnings
+import traceback
import mailman.config.config
import mailman.core.logging
+from mailman.core.i18n import _
from mailman.interfaces.database import IDatabaseFactory
from mailman.utilities.modules import call_name
from pkg_resources import resource_string as resource_bytes
@@ -133,7 +136,7 @@ def initialize_2(debug=False, propagate_logs=None, testing=False):
* Database
* Logging
- * Pre-hook
+ * Plugin's pre_hook
* Rules
* Chains
* Pipelines
@@ -146,10 +149,34 @@ def initialize_2(debug=False, propagate_logs=None, testing=False):
"""
# Create the queue and log directories if they don't already exist.
mailman.core.logging.initialize(propagate_logs)
- # Run the pre-hook if there is one.
+ # Initialize plugins
+ from mailman.core.plugins import initialize as initialize_plugins
+ initialize_plugins()
+ # Check for deprecated features in config.
config = mailman.config.config
- if config.mailman.pre_hook:
+ if config.mailman.pre_hook: # pragma: nocover
+ warnings.warn(
+ _('The pre_hook configuration value has been replaced by the '
+ 'plugins infrastructure.'), UserWarning)
call_name(config.mailman.pre_hook)
+ # Run the plugin pre_hooks, if one fails, disable the offending plugin.
+ for name in list(config.plugins.keys()):
+ plugin = config.plugins[name]
+ try:
+ plugin.pre_hook()
+ except: # pragma: nocover
+ traceback.print_exc()
+ warnings.warn(_('Plugin $name failed to run its pre_hook,'
+ 'it will be disabled and its components'
+ 'wont be loaded.'), RuntimeWarning)
+ # It failed, push disabling overlay to config. This will stop
+ # components from being loaded.
+ config.push(name + '_error', """\
+[plugin.{}]
+enable: no
+ """.format(name))
+ # And forget about it. This will stop running its post_hook.
+ del config.plugins[name]
# Instantiate the database class, ensure that it's of the right type, and
# initialize it. Then stash the object on our configuration object.
utility_name = ('testing' if testing else 'production')
@@ -171,12 +198,23 @@ def initialize_2(debug=False, propagate_logs=None, testing=False):
def initialize_3():
"""Third initialization step.
- * Post-hook
+ * Plugin's post_hook
"""
- # Run the post-hook if there is one.
+ # Run the plugin post_hooks
config = mailman.config.config
- if config.mailman.post_hook:
+ if config.mailman.post_hook: # pragma: nocover
+ warnings.warn(
+ _('The post_hook configuration value has been replaced by the '
+ 'plugins infrastructure.'), UserWarning)
call_name(config.mailman.post_hook)
+ for plugin in config.plugins.values():
+ try:
+ plugin.post_hook()
+ except: # pragma: nocover
+ # A post_hook may fail, here we just hope for the best that the
+ # plugin can work even if it post_hook failed as it's components
+ # are already loaded.
+ pass
@public