~mailman-coders/mailman/2.1

« back to all changes in this revision

Viewing changes to bin/rmlist

  • Committer: bwarsaw
  • Date: 2003-04-20 04:02:13 UTC
  • Revision ID: vcs-imports@canonical.com-20030420040213-6m49i04tg91cgmk0
Backporting from the trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! @PYTHON@
2
2
#
3
 
# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc.
 
3
# Copyright (C) 1998-2003 by the Free Software Foundation, Inc.
4
4
#
5
5
# This program is free software; you can redistribute it and/or
6
6
# modify it under the terms of the GNU General Public License
7
7
# as published by the Free Software Foundation; either version 2
8
8
# of the License, or (at your option) any later version.
9
 
 
9
#
10
10
# This program is distributed in the hope that it will be useful,
11
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
13
# GNU General Public License for more details.
14
 
 
14
#
15
15
# You should have received a copy of the GNU General Public License
16
 
# along with this program; if not, write to the Free Software 
 
16
# along with this program; if not, write to the Free Software
17
17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
18
 
19
19
"""Remove the components of a mailing list with impunity - beware!
47
47
from Mailman import MailList
48
48
from Mailman.i18n import _
49
49
 
 
50
try:
 
51
    True, False
 
52
except NameError:
 
53
    True = 1
 
54
    False = 0
 
55
 
50
56
 
51
57
 
52
58
def usage(code, msg=''):
61
67
 
62
68
 
63
69
 
64
 
def remove_it(listname, dir, msg):
65
 
    if os.path.islink(dir):
66
 
        print _('Removing %(msg)s')
67
 
        os.unlink(dir)
68
 
    elif os.path.isdir(dir):
69
 
        print _('Removing %(msg)s')
70
 
        shutil.rmtree(dir)
 
70
def remove_it(listname, filename, msg):
 
71
    if os.path.islink(filename):
 
72
        print _('Removing %(msg)s')
 
73
        os.unlink(filename)
 
74
    elif os.path.isdir(filename):
 
75
        print _('Removing %(msg)s')
 
76
        shutil.rmtree(filename)
 
77
    elif os.path.isfile(filename):
 
78
        os.unlink(filename)
71
79
    else:
72
 
        print _('%(listname)s %(msg)s not found as %(dir)s')
 
80
        print _('%(listname)s %(msg)s not found as %(filename)s')
73
81
 
74
82
 
75
83
 
84
92
        usage(1)
85
93
    listname = args[0].lower().strip()
86
94
 
87
 
    removeArchives = 0
 
95
    removeArchives = False
88
96
    for opt, arg in opts:
89
97
        if opt in ('-a', '--archives'):
90
 
            removeArchives = 1
 
98
            removeArchives = True
91
99
        elif opt in ('-h', '--help'):
92
100
            usage(0)
93
101
 
94
102
    if not Utils.list_exists(listname):
95
 
        if not removeArchives:
96
 
            usage(1, _('No such list (or list already deleted): %(listname)s'))
97
 
        else:
98
 
            print _(
 
103
        if not removeArchives:
 
104
            usage(1, _('No such list (or list already deleted): %(listname)s'))
 
105
        else:
 
106
            print _(
99
107
                'No such list: %(listname)s.  Removing its residual archives.')
100
108
 
101
109
    if not removeArchives:
104
112
 
105
113
    REMOVABLES = []
106
114
    if Utils.list_exists(listname):
107
 
        mlist = MailList.MailList(listname, lock=0)
108
 
 
109
 
        # Do the MTA-specific list deletion tasks
110
 
        if mm_cfg.MTA:
111
 
            modname = 'Mailman.MTA.' + mm_cfg.MTA
112
 
            __import__(modname)
113
 
            sys.modules[modname].remove(mlist)
114
 
 
115
 
        REMOVABLES = [
116
 
            (os.path.join('lists', listname), _('list info')),
 
115
        mlist = MailList.MailList(listname, lock=0)
 
116
 
 
117
        # Do the MTA-specific list deletion tasks
 
118
        if mm_cfg.MTA:
 
119
            modname = 'Mailman.MTA.' + mm_cfg.MTA
 
120
            __import__(modname)
 
121
            sys.modules[modname].remove(mlist)
 
122
 
 
123
        REMOVABLES = [
 
124
            (os.path.join('lists', listname), _('list info')),
117
125
            ]
118
126
 
 
127
    # Remove any stale locks associated with the list
 
128
    for filename in os.listdir(mm_cfg.LOCK_DIR):
 
129
        fn_listname = filename.split('.')[0]
 
130
        if fn_listname == listname:
 
131
            REMOVABLES.append((os.path.join(mm_cfg.LOCK_DIR, filename),
 
132
                               _('stale lock file')))
 
133
 
119
134
    if removeArchives:
120
135
        REMOVABLES.extend([
121
 
            (os.path.join('archives', 'private', listname),
122
 
             _('private archives')),
123
 
            (os.path.join('archives', 'private', listname + '.mbox'),
124
 
             _('private archives')),
125
 
            (os.path.join('archives', 'public', listname),
 
136
            (os.path.join('archives', 'private', listname),
 
137
             _('private archives')),
 
138
            (os.path.join('archives', 'private', listname + '.mbox'),
 
139
             _('private archives')),
 
140
            (os.path.join('archives', 'public', listname),
126
141
             _('public archives')),
127
 
            (os.path.join('archives', 'public', listname + '.mbox'),
 
142
            (os.path.join('archives', 'public', listname + '.mbox'),
128
143
             _('public archives')),
129
144
            ])
130
145