3
# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc.
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; either version 2
8
# of the License, or (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
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
17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
"""Rebuild a list's archive.
21
Use this command to rebuild the archives for a mailing list. You may want to
22
do this if you edit some messages in an archive, or remove some messages from
25
Usage: %(PROGRAM)s [options] <listname> [<mbox>]
29
Print this help message and exit.
32
Make the archiver output less verbose.
35
First wipe out the original archive before regenerating. You usually
36
want to specify this argument unless you're generating the archive in
41
Start indexing at article N, where article 0 is the first in the mbox.
46
End indexing at article M. This script is not very efficient with
47
respect to memory management, and for large archives, it may not be
48
possible to index the mbox entirely. For that reason, you can specify
49
the start and end article numbers.
51
Where <mbox> is the path to a list's complete mbox archive. Usually this will
52
be some path in the archives/private directory. For example:
54
%% bin/arch mylist archives/private/mylist.mbox/mylist.mbox
56
<mbox> is optional. If it is missing, it is calculated.
65
from Mailman import mm_cfg
66
from Mailman import Errors
68
from Mailman.MailList import MailList
69
from Mailman.Archiver.HyperArch import HyperArchive
70
from Mailman.LockFile import LockFile
71
from Mailman import i18n
76
i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
80
def usage(code, msg=''):
85
print >> fd, _(__doc__)
93
# get command line arguments
95
opts, args = getopt.getopt(
96
sys.argv[1:], 'hs:e:q',
97
['help', 'start', 'end', 'quiet', 'wipe'])
98
except getopt.error, msg:
105
for opt, arg in opts:
106
if opt in ('-h', '--help'):
108
elif opt in ('-s', '--start'):
113
elif opt in ('-e', '--end'):
118
elif opt in ('-q', '--quiet'):
120
elif opt == '--wipe':
125
usage(1, _('listname is required'))
126
listname = args[0].lower().strip()
136
# open the mailing list object
141
mlist = MailList(listname)
142
except Errors.MMListError, e:
143
usage(2, _('No such list "%(listname)s"\n%(e)s'))
145
mbox = mlist.ArchiveFileName()
147
i18n.set_language(mlist.preferred_language)
148
# lay claim to the archive's lock file. this is so no other post can
149
# mess up the archive while we're glomming it. we pick a suitably
150
# long period of time for the lock lifetime, however we really don't
151
# know how long it will take.
153
# XXX: processUnixMailbox() should refresh the lock.
155
# XXX: this may not be necessary because I think we lay claim to the
156
# list lock up above, although that may be too short to be of use (and
157
# maybe we don't really want to lock the list anyway).
159
lockfile = os.path.join(mm_cfg.LOCK_DIR, mlist._internal_name) + \
161
# set the lock lifetime to 3 hours. XXX is this reasonable???
162
lock = LockFile(lockfile, lifetime=3*60*60)
164
# Maybe wipe the old archives
166
shutil.rmtree(mlist.archive_dir())
170
usage(3, _('Cannot open mbox file %(mbox)s: %(msg)s'))
172
archiver = HyperArchive(mlist)
173
archiver.VERBOSE = verbose
175
archiver.processUnixMailbox(fp, start, end)
186
if __name__ == '__main__':