------------------------------------------------------------
revno: 6773
committer: Barry Warsaw <[email protected]>
branch nick: 3.0
timestamp: Sun 2009-08-16 09:32:10 -0400
message:
  Refactor the subcommands so that the infrastructure does more of the menial
  tasks.  This also let's the bin/mailman command sort its subcommands for help
  printing.
  
  Add the outline of a 'members' subcommand.
added:
  src/mailman/commands/cli_members.py
modified:
  src/mailman/bin/mailman.py
  src/mailman/commands/cli_help.py
  src/mailman/commands/cli_info.py
  src/mailman/commands/cli_lists.py
  src/mailman/interfaces/command.py


--
lp:mailman
https://code.launchpad.net/~mailman-coders/mailman/3.0

Your team Mailman Checkins is subscribed to branch lp:mailman.
To unsubscribe from this branch go to 
https://code.launchpad.net/~mailman-coders/mailman/3.0/+edit-subscription.
=== modified file 'src/mailman/bin/mailman.py'
--- src/mailman/bin/mailman.py	2009-08-09 15:25:59 +0000
+++ src/mailman/bin/mailman.py	2009-08-16 13:32:10 +0000
@@ -60,10 +60,26 @@
     # 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)
-        command.add(parser, subparser)
+        subcommands.append(command)
+    # --help should display the subcommands by alphabetical order, except that
+    # 'mailman help' should be first.
+    def sort_function(command, other):
+        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.

=== modified file 'src/mailman/commands/cli_help.py'
--- src/mailman/commands/cli_help.py	2009-08-09 15:25:59 +0000
+++ src/mailman/commands/cli_help.py	2009-08-16 13:32:10 +0000
@@ -32,16 +32,16 @@
 
 
 class Help:
-    """The `help` subcommand."""
+    # Lowercase, to match argparse's default --help text.
+    """show this help message and exit"""
 
     implements(ICLISubCommand)
 
-    def add(self, parser, subparser):
+    name = 'help'
+
+    def add(self, parser, command_parser):
         """See `ICLISubCommand`."""
         self.parser = parser
-        help_parser = subparser.add_parser(
-            'help', help=('show this help message and exit'))
-        help_parser.set_defaults(func=self.process)
 
     def process(self, args):
         """See `ICLISubCommand`."""

=== modified file 'src/mailman/commands/cli_info.py'
--- src/mailman/commands/cli_info.py	2009-08-12 04:31:37 +0000
+++ src/mailman/commands/cli_info.py	2009-08-16 13:32:10 +0000
@@ -37,16 +37,15 @@
 
 
 class Info:
-    """The `info` subcommand."""
+    """Information about this Mailman instance."""
 
     implements(ICLISubCommand)
 
-    def add(self, parser, subparser):
+    name = 'info'
+
+    def add(self, parser, command_parser):
         """See `ICLISubCommand`."""
-        info_parser = subparser.add_parser(
-            'info', help=_('Information about this Mailman instance.'))
-        info_parser.set_defaults(func=self.process)
-        info_parser.add_argument(
+        command_parser.add_argument(
             '-o', '--output',
             action='store', help=_("""\
             File to send the output to.  If not given, standard output is

=== modified file 'src/mailman/commands/cli_lists.py'
--- src/mailman/commands/cli_lists.py	2009-08-15 00:39:43 +0000
+++ src/mailman/commands/cli_lists.py	2009-08-16 13:32:10 +0000
@@ -44,31 +44,30 @@
 
 
 class Lists:
-    """The `lists` subcommand."""
+    """List all mailing lists"""
 
     implements(ICLISubCommand)
 
-    def add(self, parser, subparser):
+    name = 'lists'
+
+    def add(self, parser, command_parser):
         """See `ICLISubCommand`."""
-        lists_parser = subparser.add_parser(
-            'lists', help=_('List all mailing lists'))
-        lists_parser.set_defaults(func=self.process)
-        lists_parser.add_argument(
+        command_parser.add_argument(
             '-a', '--advertised',
             default=False, action='store_true',
             help=_(
                 'List only those mailing lists that are publicly advertised'))
-        lists_parser.add_argument(
+        command_parser.add_argument(
             '-b', '--bare',
             default=False, action='store_true',
             help=_('Show only the list name, with no description'))
-        lists_parser.add_argument(
+        command_parser.add_argument(
             '-d', '--domain',
             action='append', help=_("""\
             List only those mailing lists hosted on the given domain, which
             must be the email host name.  Multiple -d options may be given.
             """))
-        lists_parser.add_argument(
+        command_parser.add_argument(
             '-f', '--full',
             default=False, action='store_true',
             help=_(
@@ -115,22 +114,20 @@
 
 
 class Create:
-    """The `create` subcommand."""
+    """Create a mailing list"""
 
     implements(ICLISubCommand)
 
-    def add(self, parser, subparser):
+    name = 'create'
+
+    def add(self, parser, command_parser):
         """See `ICLISubCommand`."""
-        self.parser = parser
-        create_parser = subparser.add_parser(
-            'create', help=_('Create a mailing list'))
-        create_parser.set_defaults(func=self.process)
-        create_parser.add_argument(
+        command_parser.add_argument(
             '--language',
             type='unicode', metavar='CODE', help=_("""\
             Set the list's preferred language to CODE, which must be a
             registered two letter language code."""))
-        create_parser.add_argument(
+        command_parser.add_argument(
             '-o', '--owner',
             type='unicode', action='append', default=[],
             dest='owners', metavar='OWNER', help=_("""\
@@ -139,23 +136,23 @@
             linked to a user.  Mailman will send a confirmation message to the
             address, but it will also send a list creation notice to the
             address.  More than one owner can be specified."""))
-        create_parser.add_argument(
+        command_parser.add_argument(
             '-n', '--notify',
             default=False, action='store_true',
             help=_("""\
             Notify the list owner by email that their mailing list has been
             created."""))
-        create_parser.add_argument(
+        command_parser.add_argument(
             '-q', '--quiet',
             default=False, action='store_true',
             help=_('Print less output.'))
-        create_parser.add_argument(
+        command_parser.add_argument(
             '-d', '--domain',
             default=False, action='store_true',
             help=_("""\
             Register the mailing list's domain if not yet registered."""))
         # Required positional argument.
-        create_parser.add_argument(
+        command_parser.add_argument(
             'listname', metavar='LISTNAME', nargs=1,
             help=_("""\
             The 'fully qualified list name', i.e. the posting address of the
@@ -221,28 +218,26 @@
 
 
 class Remove:
-    """The `remove` subcommand."""
+    """Remove a mailing list"""
 
     implements(ICLISubCommand)
 
-    def add(self, parser, subparser):
+    name = 'remove'
+
+    def add(self, parser, command_parser):
         """See `ICLISubCommand`."""
-        self.parser = parser
-        remove_parser = subparser.add_parser(
-            'remove', help=_('Remove a mailing list'))
-        remove_parser.set_defaults(func=self.process)
-        remove_parser.add_argument(
+        command_parser.add_argument(
             '-a', '--archives',
             default=False, action='store_true',
             help=_("""\
 Remove the list's archives too, or if the list has already been deleted,
 remove any residual archives."""))
-        remove_parser.add_argument(
+        command_parser.add_argument(
             '-q', '--quiet',
             default=False, action='store_true',
             help=_('Suppress status messages'))
         # Required positional argument.
-        remove_parser.add_argument(
+        command_parser.add_argument(
             'listname', metavar='LISTNAME', nargs=1,
             help=_("""\
             The 'fully qualified list name', i.e. the posting address of the

=== added file 'src/mailman/commands/cli_members.py'
--- src/mailman/commands/cli_members.py	1970-01-01 00:00:00 +0000
+++ src/mailman/commands/cli_members.py	2009-08-16 13:32:10 +0000
@@ -0,0 +1,46 @@
+# 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 'members' subcommand."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+    'Members',
+    ]
+
+
+from zope.interface import implements
+
+from mailman.i18n import _
+from mailman.interfaces.command import ICLISubCommand
+
+
+
+class Members:
+    """Manage list memberships"""
+
+    implements(ICLISubCommand)
+
+    name = 'members'
+
+    def add(self, parser, command_parser):
+        """See `ICLISubCommand`."""
+
+    def process(self, args):
+        """See `ICLISubCommand`."""

=== modified file 'src/mailman/interfaces/command.py'
--- src/mailman/interfaces/command.py	2009-08-09 15:25:59 +0000
+++ src/mailman/interfaces/command.py	2009-08-16 13:32:10 +0000
@@ -73,12 +73,16 @@
 class ICLISubCommand(Interface):
     """A command line interface subcommand."""
 
-    def add(parser, subparser):
+    name = Attribute('The command name; must be unique')
+
+    __doc__ = Attribute('The command short help')
+
+    def add(parser, command_parser):
         """Add the subcommand to the subparser.
 
         :param parser: The argument parser.
         :type parser: `argparse.ArgumentParser`
-        :param subparser: The argument subparser.
+        :param subparser: The command subparser.
         :type subparser: `argparse.ArgumentParser`
         """
 

_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to