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
"""Re-generate the Pipermail gzip'd archive flat files.
21
This script should be run nightly from cron. When run from the command line,
22
the following usage is understood:
24
Usage: %(program)s [-v] [-h] [listnames]
29
print each file as it's being gzip'd
33
print this message and exit
36
Optionally, only compress the .txt files for the named lists. Without
37
this, all archivable lists are processed.
53
# mm_cfg must be imported before the other modules, due to the side-effect of
54
# it hacking sys.paths to include site-packages. Without this, running this
55
# script from cron with python -S will fail.
56
from Mailman import mm_cfg
57
from Mailman import Utils
58
from Mailman import MailList
65
def usage(code, msg=''):
70
print >> fd, _(__doc__) % globals()
77
def compress(txtfile):
79
print "gzip'ing:", txtfile
81
outfp = gzip.open(txtfile+'.gz', 'wb', 6)
82
outfp.write(infp.read())
91
opts, args = getopt.getopt(sys.argv[1:], 'vh', ['verbose', 'help'])
92
except getopt.error, msg:
97
if opt in ('-h', '--help'):
99
elif opt in ('-v', '--verbose'):
102
# limit to the specified lists?
106
listnames = Utils.list_names()
108
# process all the specified lists
109
for name in listnames:
110
mlist = MailList.MailList(name, lock=0)
111
if not mlist.archive:
113
dir = mlist.archive_dir()
115
allfiles = os.listdir(dir)
117
# has the list received any messages? if not, last_post_time will
118
# be zero, so it's not really a bogus archive dir.
119
if mlist.last_post_time > 0:
120
print 'List', name, 'has a bogus archive_directory:', dir
123
print 'Processing list:', name
128
# stat both the .txt and .txt.gz files and append them only if
129
# the former is newer than the latter.
130
txtfile = os.path.join(dir, f)
131
gzpfile = txtfile + '.gz'
132
txt_mtime = os.stat(txtfile)[ST_MTIME]
134
gzp_mtime = os.stat(gzpfile)[ST_MTIME]
137
if txt_mtime > gzp_mtime:
138
files.append(txtfile)
144
if __name__ == '__main__' and \
145
gzip is not None and \
146
mm_cfg.ARCHIVE_TO_MBOX in (1, 2) and \
147
not mm_cfg.GZIP_ARCHIVE_TXT_FILES:
148
# we're only going to run the nightly archiver if messages are archived to
149
# the mbox, and the gzip file is not created on demand (i.e. for every
150
# individual post). This is the normal mode of operation. Also, be sure
151
# we can actually import the gzip module!
152
omask = os.umask(002)