summaryrefslogtreecommitdiff
path: root/Mailman/bin/rmlist.py
diff options
context:
space:
mode:
authorbwarsaw2006-04-28 05:16:18 +0000
committerbwarsaw2006-04-28 05:16:18 +0000
commit3f5ae6b680e0125f5ae433aaa344fe530fada80b (patch)
treee5367ac000a8981f1e518a99111b779e557b1532 /Mailman/bin/rmlist.py
parent85e02a8e0ac388dcec48481530c237cbe9b379f9 (diff)
downloadmailman-3f5ae6b680e0125f5ae433aaa344fe530fada80b.tar.gz
mailman-3f5ae6b680e0125f5ae433aaa344fe530fada80b.tar.zst
mailman-3f5ae6b680e0125f5ae433aaa344fe530fada80b.zip
Diffstat (limited to 'Mailman/bin/rmlist.py')
-rwxr-xr-xMailman/bin/rmlist.py134
1 files changed, 53 insertions, 81 deletions
diff --git a/Mailman/bin/rmlist.py b/Mailman/bin/rmlist.py
index fbaf30641..e2d41c8d9 100755
--- a/Mailman/bin/rmlist.py
+++ b/Mailman/bin/rmlist.py
@@ -1,6 +1,4 @@
-#! @PYTHON@
-#
-# Copyright (C) 1998-2003 by the Free Software Foundation, Inc.
+# Copyright (C) 1998-2006 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -14,125 +12,99 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
-"""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.
-
-Usage:
- rmlist [-a] [-h] listname
-
-Where:
- --archives
- -a
- Remove the list's archives too, or if the list has already been
- deleted, remove any residual archives.
-
- --help
- -h
- Print this help message and exit.
-
-"""
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
import os
import sys
-import getopt
import shutil
+import optparse
-import paths
-from Mailman import mm_cfg
-from Mailman import Utils
from Mailman import MailList
+from Mailman import Utils
+from Mailman import mm_cfg
from Mailman.i18n import _
-try:
- True, False
-except NameError:
- True = 1
- False = 0
-
-
-
-def usage(code, msg=''):
- if code:
- fd = sys.stderr
- else:
- fd = sys.stdout
- print >> fd, _(__doc__)
- if msg:
- print >> fd, msg
- sys.exit(code)
+__i18n_templates__ = True
def remove_it(listname, filename, msg):
if os.path.islink(filename):
- print _('Removing %(msg)s')
+ print _('Removing $msg')
os.unlink(filename)
elif os.path.isdir(filename):
- print _('Removing %(msg)s')
+ print _('Removing $msg')
shutil.rmtree(filename)
elif os.path.isfile(filename):
os.unlink(filename)
else:
- print _('%(listname)s %(msg)s not found as %(filename)s')
+ print _('$listname $msg not found as $filename')
-def main():
- try:
- opts, args = getopt.getopt(sys.argv[1:], 'ah',
- ['archives', 'help'])
- except getopt.error, msg:
- usage(1, msg)
+def parseargs():
+ parser = optparse.OptionParser(version='GNU Mailman ' + mm_cfg.VERSION,
+ usage=_("""\
+%%prog [options] listname
- if len(args) <> 1:
- usage(1)
- listname = args[0].lower().strip()
+Remove the components of a mailing list with impunity - beware!
- removeArchives = False
- for opt, arg in opts:
- if opt in ('-a', '--archives'):
- removeArchives = True
- elif opt in ('-h', '--help'):
- usage(0)
+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.
+"""))
+ 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."""))
+ opts, args = parser.parse_args()
+ if not args:
+ parser.print_help()
+ print >> sys.stderr, _('Missing listname')
+ sys.exit(1)
+ if len(args) > 1:
+ parser.print_help()
+ print >> sys.stderr, _('Unexpected arguments')
+ sys.exit(1)
+ return parser, opts, args
+
+
+def main():
+ parser, opts, args = parseargs()
+ listname = args[0].lower().strip()
if not Utils.list_exists(listname):
- if not removeArchives:
- usage(1, _('No such list (or list already deleted): %(listname)s'))
+ if not opts.archives:
+ print >> sys.stderr, _(
+ 'No such list (or list already deleted): $listname')
+ sys.exit(1)
else:
print _(
- 'No such list: %(listname)s. Removing its residual archives.')
+ 'No such list: $listname. Removing its residual archives.')
- if not removeArchives:
+ if not opts.archives:
print _('Not removing archives. Reinvoke with -a to remove them.')
-
- REMOVABLES = []
+ removeables = []
if Utils.list_exists(listname):
- mlist = MailList.MailList(listname, lock=0)
-
+ mlist = MailList.MailList(listname, lock=False)
# Do the MTA-specific list deletion tasks
if mm_cfg.MTA:
modname = 'Mailman.MTA.' + mm_cfg.MTA
__import__(modname)
sys.modules[modname].remove(mlist)
- REMOVABLES = [
- (os.path.join('lists', listname), _('list info')),
- ]
+ removeables.append((os.path.join('lists', listname), _('list info')))
# Remove any stale locks associated with the list
for filename in os.listdir(mm_cfg.LOCK_DIR):
fn_listname = filename.split('.')[0]
if fn_listname == listname:
- REMOVABLES.append((os.path.join(mm_cfg.LOCK_DIR, filename),
- _('stale lock file')))
+ removeables.append((os.path.join(mm_cfg.LOCK_DIR, filename),
+ _('stale lock file')))
- if removeArchives:
- REMOVABLES.extend([
+ if opts.archives:
+ removeables.extend([
(os.path.join('archives', 'private', listname),
_('private archives')),
(os.path.join('archives', 'private', listname + '.mbox'),
@@ -143,9 +115,9 @@ def main():
_('public archives')),
])
- for dirtmpl, msg in REMOVABLES:
- dir = os.path.join(mm_cfg.VAR_PREFIX, dirtmpl)
- remove_it(listname, dir, msg)
+ for dirtmpl, msg in removeables:
+ path = os.path.join(mm_cfg.VAR_PREFIX, dirtmpl)
+ remove_it(listname, path, msg)