Ejemplo n.º 1
0
def initialize_2(debug=False, propagate_logs=None, testing=False):
    """Second initialization step.

    * Database
    * Logging
    * Plugin pre_hook()'s
    * Rules
    * Chains
    * Pipelines
    * Commands

    :param debug: Should the database layer be put in debug mode?
    :type debug: boolean
    :param propagate_logs: Should the log output propagate to stderr?
    :type propagate_logs: boolean or None
    """
    # Create the queue and log directories if they don't already exist.
    mailman.core.logging.initialize(propagate_logs)
    # Initialize plugins
    from mailman.plugins.initialize import initialize as initialize_plugins
    initialize_plugins()
    # Check for deprecated features in config.
    config = mailman.config.config
    if len(config.mailman.pre_hook) > 0:  # pragma: nocover
        log = logging.getLogger('mailman.plugins')
        log.warning(
            'The [mailman]pre_hook configuration value has been replaced '
            "by the plugins infrastructure, and won't be called.")
    # Run the plugin pre_hooks, if one fails, disable the offending plugin.
    for name in config.plugins:  # pragma: nocover
        plugin = config.plugins[name]
        if hasattr(plugin, 'pre_hook'):
            try:
                plugin.pre_hook()
            except Exception:  # pragma: nocover
                log = logging.getLogger('mailman.plugins')
                log.exception('Plugin failed to run its pre_hook: {}'
                              'It will be disabled and its components '
                              "won't be loaded.".format(name))
                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')
    config.db = getUtility(IDatabaseFactory, utility_name).create()
    # Initialize the rules and chains.  Do the imports here so as to avoid
    # circular imports.
    from mailman.app.commands import initialize as initialize_commands
    from mailman.core.chains import initialize as initialize_chains
    from mailman.core.pipelines import initialize as initialize_pipelines
    from mailman.core.rules import initialize as initialize_rules
    # Order here is somewhat important.
    initialize_rules()
    initialize_chains()
    initialize_pipelines()
    initialize_commands()
Ejemplo n.º 2
0
def initialize_2(debug=False, propagate_logs=None):
    """Second initialization step.

    * Logging
    * Pre-hook
    * Rules
    * Chains
    * Pipelines
    * Commands

    :param debug: Should the database layer be put in debug mode?
    :type debug: boolean
    :param propagate_logs: Should the log output propagate to stderr?
    :type propagate_logs: boolean or None
    """
    # 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.
    config = mailman.config.config
    if config.mailman.pre_hook:
        call_name(config.mailman.pre_hook)
    # Instantiate the database class, ensure that it's of the right type, and
    # initialize it.  Then stash the object on our configuration object.
    database_class = config.database['class']
    database = call_name(database_class)
    verifyObject(IDatabase, database)
    database.initialize(debug)
    config.db = database
    # Initialize the rules and chains.  Do the imports here so as to avoid
    # circular imports.
    from mailman.app.commands import initialize as initialize_commands
    from mailman.app.events import initialize as initialize_events
    from mailman.core.chains import initialize as initialize_chains
    from mailman.core.pipelines import initialize as initialize_pipelines
    from mailman.core.rules import initialize as initialize_rules
    # Order here is somewhat important.
    initialize_rules()
    initialize_chains()
    initialize_pipelines()
    initialize_commands()
    initialize_events()
Ejemplo n.º 3
0
def initialize_2(debug=False, propagate_logs=None, testing=False):
    """Second initialization step.

    * Database
    * Logging
    * Pre-hook
    * Rules
    * Chains
    * Pipelines
    * Commands

    :param debug: Should the database layer be put in debug mode?
    :type debug: boolean
    :param propagate_logs: Should the log output propagate to stderr?
    :type propagate_logs: boolean or None
    """
    # 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.
    config = mailman.config.config
    if config.mailman.pre_hook:
        call_name(config.mailman.pre_hook)
    # 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')
    config.db = getUtility(IDatabaseFactory, utility_name).create()
    # Initialize the rules and chains.  Do the imports here so as to avoid
    # circular imports.
    from mailman.app.commands import initialize as initialize_commands
    from mailman.core.chains import initialize as initialize_chains
    from mailman.core.pipelines import initialize as initialize_pipelines
    from mailman.core.rules import initialize as initialize_rules
    # Order here is somewhat important.
    initialize_rules()
    initialize_chains()
    initialize_pipelines()
    initialize_commands()