diff options
| author | Barry Warsaw | 2009-08-09 10:49:35 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2009-08-09 10:49:35 -0400 |
| commit | 9cb2d844baf1ec47bed25fd48e5762ab641b5498 (patch) | |
| tree | 071f4c18deec29c8c270bef8d8d3fd94b6cdaec8 /src/mailman/bin | |
| parent | c4a053b184f16156cafd984b01c055d70414c4b6 (diff) | |
| download | mailman-9cb2d844baf1ec47bed25fd48e5762ab641b5498.tar.gz mailman-9cb2d844baf1ec47bed25fd48e5762ab641b5498.tar.zst mailman-9cb2d844baf1ec47bed25fd48e5762ab641b5498.zip | |
A start on the 'mailman' subcommand layout, with the help of argparse. Right
now the only subcommand is 'lists' which displays all mailing lists like the
old bin/list_lists command did (which is now removed).
Remove bin/version since 'bin/mailman --version' does this for us.
Simplify the calculation of the bin scripts; there will be many fewer of them.
Extend i18n to use a class based structure. By default, all i18n strings are
dedented after translation and substitution, which improves command line
help. The class structure allows for overriding this behavior.
Diffstat (limited to 'src/mailman/bin')
| -rw-r--r-- | src/mailman/bin/__init__.py | 61 | ||||
| -rw-r--r-- | src/mailman/bin/list_lists.py | 104 | ||||
| -rw-r--r-- | src/mailman/bin/mailman.py | 79 | ||||
| -rw-r--r-- | src/mailman/bin/master.py | 5 | ||||
| -rw-r--r-- | src/mailman/bin/qrunner.py | 10 | ||||
| -rw-r--r-- | src/mailman/bin/version.py | 48 |
6 files changed, 92 insertions, 215 deletions
diff --git a/src/mailman/bin/__init__.py b/src/mailman/bin/__init__.py index d61693c5e..e69de29bb 100644 --- a/src/mailman/bin/__init__.py +++ b/src/mailman/bin/__init__.py @@ -1,61 +0,0 @@ -# Copyright (C) 2007-2009 by the Free Software Foundation, Inc. -# -# This file is part of GNU Mailman. -# -# GNU Mailman is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation, either version 3 of the License, or (at your option) -# any later version. -# -# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along with -# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. - -__all__ = [ - 'add_members', - 'arch', - 'bounces', - 'bumpdigests', - 'check_perms', - 'checkdbs', - 'cleanarch', - 'config_list', - 'confirm', - 'create_list', - 'disabled', - 'dumpdb', - 'export', - 'find_member', - 'gate_news', - 'genaliases', - 'import', - 'inject', - 'join', - 'leave', - 'list_lists', - 'list_members', - 'list_owners', - 'mailmanctl', - 'make_instance', - 'master', - 'mmsitepass', - 'nightly_gzip', - 'owner', - 'post', - 'qrunner', - 'remove_list', - 'request', - 'senddigests', - 'set_members', - 'show_config', - 'show_qfiles', - 'testall', - 'unshunt', - 'update', - 'version', - 'withlist', - ] diff --git a/src/mailman/bin/list_lists.py b/src/mailman/bin/list_lists.py deleted file mode 100644 index ea1640910..000000000 --- a/src/mailman/bin/list_lists.py +++ /dev/null @@ -1,104 +0,0 @@ -# Copyright (C) 1998-2009 by the Free Software Foundation, Inc. -# -# This file is part of GNU Mailman. -# -# GNU Mailman is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation, either version 3 of the License, or (at your option) -# any later version. -# -# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along with -# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. - -from mailman.config import config -from mailman.i18n import _ -from mailman.options import Options - - - -class ScriptOptions(Options): - usage = _("""\ -%prog [options] - -List all mailing lists.""") - - def add_options(self): - super(ScriptOptions, self).add_options() - self.parser.add_option( - '-a', '--advertised', - default=False, action='store_true', - help=_("""\ -List only those mailing lists that are publicly advertised""")) - self.parser.add_option( - '-b', '--bare', - default=False, action='store_true', - help=_("""\ -Displays only the list name, with no description.""")) - self.parser.add_option( - '-d', '--domain', - default=[], type='string', action='append', - dest='domains', help=_("""\ -List only those mailing lists that match the given virtual domain, which may -be either the email host or the url host name. Multiple -d options may be -given.""")) - self.parser.add_option( - '-f', '--full', - default=False, action='store_true', - help=_("""\ -Print the full list name, including the posting address.""")) - - def sanity_check(self): - if len(self.arguments) > 0: - self.parser.error(_('Unexpected arguments')) - - - -def main(): - options = ScriptOptions() - options.initialize() - - mlists = [] - longest = 0 - - listmgr = config.db.list_manager - for fqdn_name in sorted(listmgr.names): - mlist = listmgr.get(fqdn_name) - if options.options.advertised and not mlist.advertised: - continue - if options.options.domains: - for domain in options.options.domains: - if domain in mlist.web_page_url or domain == mlist.host_name: - mlists.append(mlist) - break - else: - mlists.append(mlist) - if options.options.full: - name = mlist.fqdn_listname - else: - name = mlist.real_name - longest = max(len(name), longest) - - if not mlists and not options.options.bare: - print _('No matching mailing lists found') - return - - if not options.options.bare: - num_mlists = len(mlists) - print _('$num_mlists matching mailing lists found:') - - format = '%%%ds - %%.%ds' % (longest, 77 - longest) - for mlist in mlists: - if options.options.full: - name = mlist.fqdn_listname - else: - name = mlist.real_name - if options.options.bare: - print name - else: - description = mlist.description or _('[no description available]') - print ' ', format % (name, description) diff --git a/src/mailman/bin/mailman.py b/src/mailman/bin/mailman.py new file mode 100644 index 000000000..42b145e67 --- /dev/null +++ b/src/mailman/bin/mailman.py @@ -0,0 +1,79 @@ +# Copyright (C) 2009 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""The 'mailman' command dispatcher.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'main', + ] + + +import os +import argparse + +from zope.interface.verify import verifyObject + +from mailman.app.finder import find_components +from mailman.core.initialize import initialize +from mailman.i18n import _ +from mailman.interfaces.command import ICLISubCommand +from mailman.version import MAILMAN_VERSION_FULL + + + +def main(): + # Create the basic parser and add all globally common options. + parser = argparse.ArgumentParser( + description=_("""\ + The GNU Mailman mailing list management system + Copyright 1998-2009 by the Free Software Foundation, Inc. + http://www.list.org + """), + formatter_class=argparse.RawDescriptionHelpFormatter, + version=MAILMAN_VERSION_FULL) + 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') + for command_class in find_components('mailman.commands', ICLISubCommand): + command = command_class() + verifyObject(ICLISubCommand, command) + command.add(subparser) + args = parser.parse_args() + if len(args.__dict__) == 0: + # No arguments or subcommands were given. + parser.print_help() + parser.exit() + # Before actually performing the subcommand, we need to initialize the + # Mailman system, and in particular, we must read the configuration file. + config_file = os.getenv('MAILMAN_CONFIG_FILE') + if config_file is None: + config_file = args.config + initialize(config_file) + # Perform the subcommand option. + args.func(args) diff --git a/src/mailman/bin/master.py b/src/mailman/bin/master.py index 58e0776bd..829468883 100644 --- a/src/mailman/bin/master.py +++ b/src/mailman/bin/master.py @@ -17,10 +17,11 @@ """Master sub-process watcher.""" +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ - 'Loop', - 'get_lock_data', + 'main', ] diff --git a/src/mailman/bin/qrunner.py b/src/mailman/bin/qrunner.py index bcda52ca6..73e701f16 100644 --- a/src/mailman/bin/qrunner.py +++ b/src/mailman/bin/qrunner.py @@ -15,6 +15,16 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +"""The queue runner.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'main', + ] + + import sys import signal import logging diff --git a/src/mailman/bin/version.py b/src/mailman/bin/version.py deleted file mode 100644 index 31fc33ec2..000000000 --- a/src/mailman/bin/version.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (C) 1998-2009 by the Free Software Foundation, Inc. -# -# This file is part of GNU Mailman. -# -# GNU Mailman is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation, either version 3 of the License, or (at your option) -# any later version. -# -# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along with -# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. - -"""Print the Mailman version.""" - -from __future__ import absolute_import, unicode_literals - -__metaclass__ = type -__all__ = [ - 'main', - ] - - -# pylint: disable-msg=W0611 -from mailman.core.system import system -from mailman.i18n import _ -from mailman.options import Options - - - -class ScriptOptions(Options): - """See `Options`.""" - usage = _("""\ -%prog - -Print the Mailman version and exit.""") - - - -def main(): - """Main entry point.""" - options = ScriptOptions() - options.initialize() - print _('Using $system.mailman_version') |
