------------------------------------------------------------
revno: 6772
committer: Barry Warsaw <[email protected]>
branch nick: 3.0
timestamp: Fri 2009-08-14 20:39:43 -0400
message:
  Add the 'mailman remove' command.
removed:
  src/mailman/bin/remove_list.py
added:
  src/mailman/commands/docs/remove.txt
modified:
  src/mailman/commands/cli_lists.py
  src/mailman/commands/docs/create.txt


--
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.
=== removed file 'src/mailman/bin/remove_list.py'
--- src/mailman/bin/remove_list.py	2009-01-05 00:41:05 +0000
+++ src/mailman/bin/remove_list.py	1970-01-01 00:00:00 +0000
@@ -1,83 +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/>.
-
-import sys
-
-from mailman.app.lifecycle import remove_list
-from mailman.config import config
-from mailman.i18n import _
-from mailman.options import MultipleMailingListOptions
-
-
-
-class ScriptOptions(MultipleMailingListOptions):
-    usage = _("""\
-%prog [options]
-
-Remove the components of a mailing list with impunity - beware!
-
-This removes (almost) all traces of a mailing list.  By default, the lists
-archives are not removed, which is very handy for retiring old lists.
-""")
-
-    def add_options(self):
-        super(ScriptOptions, self).add_options()
-        self.parser.add_option(
-            '-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."""))
-        self.parser.add_option(
-            '-q', '--quiet',
-            default=False, action='store_true',
-            help=_('Suppress status messages'))
-
-    def sanity_check(self):
-        if len(self.options.listnames) == 0:
-            self.parser.error(_('Nothing to do'))
-        if len(self.arguments) > 0:
-            self.parser.error(_('Unexpected arguments'))
-
-
-
-def main():
-    options = ScriptOptions()
-    options.initialize()
-
-    for fqdn_listname in options.options.listnames:
-        if not options.options.quiet:
-            print _('Removing list: $fqdn_listname')
-        mlist = config.db.list_manager.get(fqdn_listname)
-        if mlist is None:
-            if options.options.archives:
-                print _("""\
-No such list: ${fqdn_listname}.  Removing its residual archives.""")
-            else:
-                print >> sys.stderr, _(
-                    'No such list (or list already deleted): $fqdn_listname')
-
-        if not options.options.archives:
-            print _('Not removing archives.  Reinvoke with -a to remove them.')
-
-        remove_list(fqdn_listname, mlist, options.options.archives)
-        config.db.commit()
-
-
-
-if __name__ == '__main__':
-    main()

=== modified file 'src/mailman/commands/cli_lists.py'
--- src/mailman/commands/cli_lists.py	2009-08-13 03:53:34 +0000
+++ src/mailman/commands/cli_lists.py	2009-08-15 00:39:43 +0000
@@ -23,13 +23,14 @@
 __all__ = [
     'Create',
     'Lists',
+    'Remove',
     ]
 
 
 from zope.interface import implements
 
 from mailman.Utils import maketext
-from mailman.app.lifecycle import create_list
+from mailman.app.lifecycle import create_list, remove_list
 from mailman.config import config
 from mailman.constants import system_preferences
 from mailman.core.errors import InvalidEmailAddress
@@ -216,3 +217,56 @@
                     _('Your new mailing list: $fqdn_listname'),
                     text, mlist.preferred_language)
                 msg.send(mlist)
+
+
+
+class Remove:
+    """The `remove` subcommand."""
+
+    implements(ICLISubCommand)
+
+    def add(self, parser, subparser):
+        """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(
+            '-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(
+            '-q', '--quiet',
+            default=False, action='store_true',
+            help=_('Suppress status messages'))
+        # Required positional argument.
+        remove_parser.add_argument(
+            'listname', metavar='LISTNAME', nargs=1,
+            help=_("""\
+            The 'fully qualified list name', i.e. the posting address of the
+            mailing list."""))
+
+    def process(self, args):
+        """See `ICLISubCommand`."""
+        def log(message):
+            if not args.quiet:
+                print message
+        assert len(args.listname) == 1, (
+            'Unexpected positional arguments: %s' % args.listname)
+        fqdn_listname = args.listname[0]
+        mlist = config.db.list_manager.get(fqdn_listname)
+        if mlist is None:
+            if args.archives:
+                log(_('No such list: $fqdn_listname; '
+                      'removing residual archives.'))
+            else:
+                log(_('No such list: $fqdn_listname'))
+                return
+        else:
+            log(_('Removed list: $fqdn_listname'))
+        if not args.archives:
+            log(_('Not removing archives.  Reinvoke with -a to remove them.'))
+        remove_list(fqdn_listname, mlist, args.archives)
+        config.db.commit()

=== modified file 'src/mailman/commands/docs/create.txt'
--- src/mailman/commands/docs/create.txt	2009-08-13 04:50:17 +0000
+++ src/mailman/commands/docs/create.txt	2009-08-15 00:39:43 +0000
@@ -2,7 +2,7 @@
 Command line list creation
 ==========================
 
-A system administrator can create mailing lists from the command line.
+A system administrator can create mailing lists by the command line.
 
     >>> class FakeArgs:
     ...     language = None

=== added file 'src/mailman/commands/docs/remove.txt'
--- src/mailman/commands/docs/remove.txt	1970-01-01 00:00:00 +0000
+++ src/mailman/commands/docs/remove.txt	2009-08-15 00:39:43 +0000
@@ -0,0 +1,81 @@
+=========================
+Command line list removal
+=========================
+
+A system administrator can remove mailing lists by the command line.
+
+    >>> from mailman.app.lifecycle import create_list
+    >>> create_list('[email protected]')
+    <mailing list "[email protected]" at ...>
+
+    >>> config.db.list_manager.get('[email protected]')
+    <mailing list "[email protected]" at ...>
+
+    >>> class FakeArgs:
+    ...     quiet = False
+    ...     archives = False
+    ...     listname = ['[email protected]']
+    >>> args = FakeArgs()
+
+    >>> from mailman.commands.cli_lists import Remove
+    >>> command = Remove()
+    >>> command.process(args)
+    Removed list: [email protected]
+    Not removing archives.  Reinvoke with -a to remove them.
+
+    >>> print config.db.list_manager.get('[email protected]')
+    None
+
+You can also remove lists quietly.
+
+    >>> from mailman.app.lifecycle import create_list
+    >>> create_list('[email protected]')
+    <mailing list "[email protected]" at ...>
+
+    >>> args.quiet = True
+    >>> command.process(args)
+
+    >>> print config.db.list_manager.get('[email protected]')
+    None
+
+
+Removing archives
+=================
+
+By default 'mailman remove' does not remove a mailing list's archives.
+
+    >>> from mailman.app.lifecycle import create_list
+    >>> create_list('[email protected]')
+    <mailing list "[email protected]" at ...>
+
+    # Fake an mbox file for the mailing list.
+    >>> import os
+    >>> def make_mbox(fqdn_listname):
+    ...     mbox_dir = os.path.join(
+    ...         config.PUBLIC_ARCHIVE_FILE_DIR, fqdn_listname + '.mbox')
+    ...     os.makedirs(mbox_dir)
+    ...     mbox_file = os.path.join(mbox_dir, fqdn_listname + '.mbox')
+    ...     with open(mbox_file, 'w') as fp:
+    ...         print >> fp, 'A message'
+    ...     assert os.path.exists(mbox_file)
+    ...     return mbox_file
+
+    >>> mbox_file = make_mbox('[email protected]')
+    >>> args.quiet = False
+    >>> command.process(args)
+    Removed list: [email protected]
+    Not removing archives.  Reinvoke with -a to remove them.
+
+    >>> os.path.exists(mbox_file)
+    True
+
+Even if the mailing list has been deleted, you can still delete the archives
+afterward.
+
+    >>> args.archives = True
+    
+    >>> command.process(args)
+    No such list: [email protected]; removing residual archives.
+
+    >>> os.path.exists(mbox_file)
+    False

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

Reply via email to