Exemple #1
0
def main():
    """bin/mailman"""
    # Create the basic parser and add all globally common options.
    parser = argparse.ArgumentParser(
        description=_("""\
        The GNU Mailman mailing list management system
        Copyright 1998-2012 by the Free Software Foundation, Inc.
        http://www.list.org
        """),
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        '-v', '--version',
        action='version', version=MAILMAN_VERSION_FULL,
        help=_('Print this version string and exit'))
    parser.add_argument(
        '-C', '--config',
        help=_("""\
        Configuration file to use.  If not given, the environment variable
        MAILMAN_CONFIG_FILE is consulted and used if set.  If neither are
        given, a default configuration file is loaded."""))
    # Look at all modules in the mailman.bin package and if they are prepared
    # to add a subcommand, let them do so.  I'm still undecided as to whether
    # this should be pluggable or not.  If so, then we'll probably have to
    # partially parse the arguments now, then initialize the system, then find
    # the plugins.  Punt on this for now.
    subparser = parser.add_subparsers(title='Commands')
    subcommands = []
    for command_class in find_components('mailman.commands', ICLISubCommand):
        command = command_class()
        verifyObject(ICLISubCommand, command)
        subcommands.append(command)
    # --help should display the subcommands by alphabetical order, except that
    # 'mailman help' should be first.
    def sort_function(command, other):
        """Sorting helper."""
        if command.name == 'help':
            return -1
        elif other.name == 'help':
            return 1
        else:
            return cmp(command.name, other.name)
    subcommands.sort(cmp=sort_function)
    for command in subcommands:
        command_parser = subparser.add_parser(
            command.name, help=_(command.__doc__))
        command.add(parser, command_parser)
        command_parser.set_defaults(func=command.process)
    args = parser.parse_args()
    if len(args.__dict__) == 0:
        # No arguments or subcommands were given.
        parser.print_help()
        parser.exit()
    # Initialize the system.  Honor the -C flag if given.
    config_path = (None if args.config is None
                   else os.path.abspath(os.path.expanduser(args.config)))
    initialize(config_path)
    # Perform the subcommand option.
    args.func(args)
Exemple #2
0
def initialize():
    """Initialize the email commands."""
    for command_class in find_components("mailman.commands", IEmailCommand):
        command = command_class()
        verifyObject(IEmailCommand, command)
        assert command_class.name not in config.commands, 'Duplicate email command "{0}" found in {1}'.format(
            command_class.name, command_class.__module__
        )
        config.commands[command_class.name] = command_class()
Exemple #3
0
def initialize():
    """Find and register all rules in all plugins."""
    # Find rules in plugins.
    for rule_class in find_components('mailman.rules', IRule):
        rule = rule_class()
        verifyObject(IRule, rule)
        assert rule.name not in config.rules, (
            'Duplicate rule "{0}" found in {1}'.format(
                rule.name, rule_class))
        config.rules[rule.name] = rule
Exemple #4
0
def initialize():
    """Initialize the pipelines."""
    # Find all handlers in the registered plugins.
    for handler_class in find_components('mailman.handlers', IHandler):
        handler = handler_class()
        verifyObject(IHandler, handler)
        assert handler.name not in config.handlers, (
            'Duplicate handler "{0}" found in {1}'.format(
                handler.name, handler_class))
        config.handlers[handler.name] = handler
    # Set up some pipelines.
    for pipeline_class in (OwnerPipeline, PostingPipeline, VirginPipeline):
        pipeline = pipeline_class()
        config.pipelines[pipeline.name] = pipeline
Exemple #5
0
def initialize():
    """Set up chains, both built-in and from the database."""
    for chain_class in find_components('mailman.chains', IChain):
        # FIXME 2010-12-28 barry: We need a generic way to disable automatic
        # instantiation of discovered classes.  This is useful not just for
        # chains, but also for rules, handlers, etc.  Ideally it should be
        # part of find_components().  For now, hard code the ones we do not
        # want to instantiate.
        if chain_class in (Chain, TerminalChainBase):
            continue
        chain = chain_class()
        verifyObject(IChain, chain)
        assert chain.name not in config.chains, (
            'Duplicate chain "{0}" found in {1} (previously: {2}'.format(
                chain.name, chain_class, config.chains[chain.name]))
        config.chains[chain.name] = chain
    # XXX Read chains from the database and initialize them.
    pass