/usr/lib/mailman/bin/arch is in mailman 1:2.1.20-1.
This file is owned by root:list, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | #! /usr/bin/python
#
# Copyright (C) 1998-2008 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
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""Rebuild a list's archive.
Use this command to rebuild the archives for a mailing list. You may want to
do this if you edit some messages in an archive, or remove some messages from
an archive.
Usage: %(PROGRAM)s [options] <listname> [<mbox>]
Where options are:
-h / --help
Print this help message and exit.
-q / --quiet
Make the archiver output less verbose.
--wipe
First wipe out the original archive before regenerating. You usually
want to specify this argument unless you're generating the archive in
chunks.
-s N
--start=N
Start indexing at article N, where article 0 is the first in the mbox.
Defaults to 0.
-e M
--end=M
End indexing at article M. This script is not very efficient with
respect to memory management, and for large archives, it may not be
possible to index the mbox entirely. For that reason, you can specify
the start and end article numbers.
Where <mbox> is the path to a list's complete mbox archive. Usually this will
be some path in the archives/private directory. For example:
%% bin/arch mylist archives/private/mylist.mbox/mylist.mbox
<mbox> is optional. If it is missing, it is calculated.
"""
import os
import sys
import getopt
import shutil
import paths
from Mailman import mm_cfg
from Mailman import Errors
from Mailman.MailList import MailList
from Mailman.Archiver.HyperArch import HyperArchive
from Mailman.LockFile import LockFile
from Mailman import i18n
_ = i18n._
PROGRAM = sys.argv[0]
i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
def usage(code, msg=''):
if code:
fd = sys.stderr
else:
fd = sys.stdout
print >> fd, _(__doc__)
if msg:
print >> fd, msg
sys.exit(code)
def main():
# get command line arguments
try:
opts, args = getopt.getopt(
sys.argv[1:], 'hs:e:q',
['help', 'start=', 'end=', 'quiet', 'wipe'])
except getopt.error, msg:
usage(1, msg)
start = None
end = None
verbose = 1
wipe = 0
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-s', '--start'):
try:
start = int(arg)
except ValueError:
usage(1)
elif opt in ('-e', '--end'):
try:
end = int(arg)
except ValueError:
usage(1)
elif opt in ('-q', '--quiet'):
verbose = 0
elif opt == '--wipe':
wipe = 1
# grok arguments
if len(args) < 1:
usage(1, _('listname is required'))
listname = args[0].lower().strip()
if len(args) < 2:
mbox = None
else:
mbox = args[1]
if len(args) > 2:
usage(1)
# open the mailing list object
mlist = None
lock = None
try:
try:
mlist = MailList(listname)
except Errors.MMListError, e:
usage(2, _('No such list "%(listname)s"\n%(e)s'))
if mbox is None:
mbox = mlist.ArchiveFileName()
i18n.set_language(mlist.preferred_language)
# lay claim to the archive's lock file. this is so no other post can
# mess up the archive while we're glomming it. we pick a suitably
# long period of time for the lock lifetime, however we really don't
# know how long it will take.
#
# XXX: processUnixMailbox() should refresh the lock.
#
# XXX: this may not be necessary because I think we lay claim to the
# list lock up above, although that may be too short to be of use (and
# maybe we don't really want to lock the list anyway).
#
lockfile = os.path.join(mm_cfg.LOCK_DIR, mlist._internal_name) + \
'.archiver.lock'
# set the lock lifetime to 3 hours. XXX is this reasonable???
lock = LockFile(lockfile, lifetime=3*60*60)
lock.lock()
# Try to open mbox before wiping old archive.
try:
fp = open(mbox)
except IOError, msg:
usage(3, _('Cannot open mbox file %(mbox)s: %(msg)s'))
# Maybe wipe the old archives
if wipe:
if mlist.scrub_nondigest:
# TK: save the attachments dir because they are not in mbox
saved = 0
try:
atchdir = os.path.join(mlist.archive_dir(), 'attachments')
savedir = os.path.join(mlist.archive_dir() + '.mbox',
'attachments')
os.rename(atchdir, savedir)
saved = 1
except:
pass
shutil.rmtree(mlist.archive_dir())
if mlist.scrub_nondigest and saved:
os.renames(savedir, atchdir)
archiver = HyperArchive(mlist)
archiver.VERBOSE = verbose
try:
archiver.processUnixMailbox(fp, start, end)
finally:
archiver.close()
fp.close()
finally:
if lock:
lock.unlock()
if mlist:
mlist.Unlock()
if __name__ == '__main__':
main()
|