3
# Copyright (C) 2008 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20
"""Cull bad and shunt queues, recommended once per day.
22
This script goes through the 'bad' and 'shunt' queue directories and,
23
if mm_cfg.BAD_SHUNT_STALE_AFTER is > 0, it removes all files more than
24
that many seconds old.
26
If mm_cfg.BAD_SHUNT_ARCHIVE_DIRECTORY is a writable directory, the old
27
files are moved there. Otherwise they are deleted.
29
Only regular files immediately subordinate to the 'bad' and 'shunt'
30
directories are processed. Anything else is skipped.
32
Usage: %(PROGRAM)s [options]
36
Print this message and exit.
47
# mm_cfg must be imported before the other modules, due to the side-effect of
48
# it hacking sys.paths to include site-packages. Without this, running this
49
# script from cron with python -S will fail.
50
from Mailman import mm_cfg
51
from Mailman.i18n import _
53
# Work around known problems with some RedHat cron daemons
55
signal.signal(signal.SIGCHLD, signal.SIG_DFL)
61
def usage(code, msg=''):
66
print >> fd, _(__doc__)
75
opts, args = getopt.getopt(
76
sys.argv[1:], 'h', ['help'])
77
except getopt.error, msg:
83
if mm_cfg.BAD_SHUNT_STALE_AFTER <= 0:
87
old = now - float(mm_cfg.BAD_SHUNT_STALE_AFTER)
88
os.stat_float_times(True)
89
adir = mm_cfg.BAD_SHUNT_ARCHIVE_DIRECTORY
90
if (adir and os.access(adir, os.W_OK | os.X_OK)
91
and stat.S_ISDIR(os.stat(adir).st_mode)):
95
print >>sys.stderr, '%s: archive directory %s not usable.' % (
98
for qdir in (mm_cfg.BADQUEUE_DIR, mm_cfg.SHUNTQUEUE_DIR):
100
names = os.listdir(qdir)
102
if e.errno <> errno.ENOENT:
103
# OK if qdir doesn't exist, else
107
pathname = os.path.join(qdir, name)
108
pstat = os.stat(pathname)
109
if not stat.S_ISREG(pstat.st_mode):
112
if pstat.st_mtime > old:
116
os.rename(pathname, os.path.join(adir, name))
122
if __name__ == '__main__':