diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/core/initialize.py | 43 | ||||
| -rw-r--r-- | src/mailman/utilities/plugins.py | 6 |
2 files changed, 36 insertions, 13 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 diff --git a/src/mailman/utilities/plugins.py b/src/mailman/utilities/plugins.py index 98a34fbca..3fb5e49bc 100644 --- a/src/mailman/utilities/plugins.py +++ b/src/mailman/utilities/plugins.py @@ -57,8 +57,8 @@ def add_pluggable_components(subpackage, interface, mapping): object's `.name` attribute, which is required. It is a fatal error if that key already exists in the mapping. - :param package: The subpackage path to search. - :type package: string + :param subpackage: The subpackage path to search. + :type subpackage: string :param interface: The interface that returned objects must conform to. Objects found must have a `.name` attribute containing a unique string. @@ -70,7 +70,7 @@ def add_pluggable_components(subpackage, interface, mapping): """ for component in find_pluggable_components(subpackage, interface): if component.name in mapping: - raise RuntimeError( + raise RuntimeError( # pragma: no cover 'Duplicate key "{}" found in {}; previously {}'.format( component.name, component, mapping[component.name])) mapping[component.name] = component |
