summaryrefslogtreecommitdiff
path: root/src/mailman/bin/mailman.py
diff options
context:
space:
mode:
authorBarry Warsaw2009-08-09 10:49:35 -0400
committerBarry Warsaw2009-08-09 10:49:35 -0400
commit9cb2d844baf1ec47bed25fd48e5762ab641b5498 (patch)
tree071f4c18deec29c8c270bef8d8d3fd94b6cdaec8 /src/mailman/bin/mailman.py
parentc4a053b184f16156cafd984b01c055d70414c4b6 (diff)
downloadmailman-9cb2d844baf1ec47bed25fd48e5762ab641b5498.tar.gz
mailman-9cb2d844baf1ec47bed25fd48e5762ab641b5498.tar.zst
mailman-9cb2d844baf1ec47bed25fd48e5762ab641b5498.zip
Diffstat (limited to 'src/mailman/bin/mailman.py')
-rw-r--r--src/mailman/bin/mailman.py79
1 files changed, 79 insertions, 0 deletions
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)