summaryrefslogtreecommitdiff
path: root/src/mailman/core/initialize.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/core/initialize.py')
-rw-r--r--src/mailman/core/initialize.py43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/mailman/core/initialize.py b/src/mailman/core/initialize.py
index 18e874552..a1314b51e 100644
--- a/src/mailman/core/initialize.py
+++ b/src/mailman/core/initialize.py
@@ -27,6 +27,7 @@ by the command line arguments.
import os
import sys
import warnings
+import traceback
import mailman.config.config
import mailman.core.logging
@@ -149,14 +150,30 @@ def initialize_2(debug=False, propagate_logs=None, testing=False):
# Initialize plugins
from mailman.core.plugins import initialize as initialize_plugins
initialize_plugins()
- # Run the plugin pre_hooks
+ # Check for deprecated features in config.
config = mailman.config.config
- if "pre_hook" in config.mailman: # pragma: no cover
+ if 'pre_hook' in config.mailman: # pragma: no cover
warnings.warn(
- "The pre_hook configuration value has been replaced by the "
- "plugins infrastructure.", DeprecationWarning)
- for plugin in config.plugins.values():
- plugin.pre_hook()
+ 'The pre_hook configuration value has been replaced by the '
+ 'plugins infrastructure.', DeprecationWarning)
+ # 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 BaseException: # pragma: no cover
+ traceback.print_exc()
+ warnings.warn('Plugin {} failed to run its pre_hook,'
+ 'it will be disabled and its components'
+ 'wont be loaded.'.format(name), 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 pot_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')
@@ -182,12 +199,18 @@ def initialize_3():
"""
# Run the plugin post_hooks
config = mailman.config.config
- if "post_hook" in config.mailman: # pragma: no cover
+ if 'post_hook' in config.mailman: # pragma: no cover
warnings.warn(
- "The post_hook configuration value has been replaced by the "
- "plugins infrastructure.", DeprecationWarning)
+ 'The post_hook configuration value has been replaced by the '
+ 'plugins infrastructure.', DeprecationWarning)
for plugin in config.plugins.values():
- plugin.post_hook()
+ try:
+ plugin.post_hook()
+ except: # pragma: no cover
+ # 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