summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/bin/remove_list.py83
-rw-r--r--src/mailman/commands/cli_lists.py56
-rw-r--r--src/mailman/commands/docs/create.txt2
-rw-r--r--src/mailman/commands/docs/remove.txt81
4 files changed, 137 insertions, 85 deletions
diff --git a/src/mailman/bin/remove_list.py b/src/mailman/bin/remove_list.py
deleted file mode 100644
index 05211b200..000000000
--- a/src/mailman/bin/remove_list.py
+++ /dev/null
@@ -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()
diff --git a/src/mailman/commands/cli_lists.py b/src/mailman/commands/cli_lists.py
index 25e39cc49..9fd401949 100644
--- a/src/mailman/commands/cli_lists.py
+++ b/src/mailman/commands/cli_lists.py
@@ -23,13 +23,14 @@ __metaclass__ = type
__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 @@ class Create:
_('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()
diff --git a/src/mailman/commands/docs/create.txt b/src/mailman/commands/docs/create.txt
index a66e2ac4b..e882b7a77 100644
--- a/src/mailman/commands/docs/create.txt
+++ b/src/mailman/commands/docs/create.txt
@@ -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
diff --git a/src/mailman/commands/docs/remove.txt b/src/mailman/commands/docs/remove.txt
new file mode 100644
index 000000000..be623ccf4
--- /dev/null
+++ b/src/mailman/commands/docs/remove.txt
@@ -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('test@example.com')
+ <mailing list "test@example.com" at ...>
+
+ >>> config.db.list_manager.get('test@example.com')
+ <mailing list "test@example.com" at ...>
+
+ >>> class FakeArgs:
+ ... quiet = False
+ ... archives = False
+ ... listname = ['test@example.com']
+ >>> args = FakeArgs()
+
+ >>> from mailman.commands.cli_lists import Remove
+ >>> command = Remove()
+ >>> command.process(args)
+ Removed list: test@example.com
+ Not removing archives. Reinvoke with -a to remove them.
+
+ >>> print config.db.list_manager.get('test@example.com')
+ None
+
+You can also remove lists quietly.
+
+ >>> from mailman.app.lifecycle import create_list
+ >>> create_list('test@example.com')
+ <mailing list "test@example.com" at ...>
+
+ >>> args.quiet = True
+ >>> command.process(args)
+
+ >>> print config.db.list_manager.get('test@example.com')
+ None
+
+
+Removing archives
+=================
+
+By default 'mailman remove' does not remove a mailing list's archives.
+
+ >>> from mailman.app.lifecycle import create_list
+ >>> create_list('test@example.com')
+ <mailing list "test@example.com" 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('test@example.com')
+ >>> args.quiet = False
+ >>> command.process(args)
+ Removed list: test@example.com
+ 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: test@example.com; removing residual archives.
+
+ >>> os.path.exists(mbox_file)
+ False