Fix the error code for a corner case.
[mailman.git] / port_me / senddigests.py
blob59c03de2de28f534fcb6934c26ee59401fdaf2f5
1 # Copyright (C) 1998-2015 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
8 # any later version.
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 import os
19 import sys
20 import optparse
22 from mailman import MailList
23 from mailman.core.i18n import _
24 from mailman.initialize import initialize
25 from mailman.version import MAILMAN_VERSION
27 # Work around known problems with some RedHat cron daemons
28 import signal
29 signal.signal(signal.SIGCHLD, signal.SIG_DFL)
33 def parseargs():
34 parser = optparse.OptionParser(version=MAILMAN_VERSION,
35 usage=_("""\
36 %prog [options]
38 Dispatch digests for lists w/pending messages and digest_send_periodic
39 set."""))
40 parser.add_option('-l', '--listname',
41 type='string', default=[], action='append',
42 dest='listnames', help=_("""\
43 Send the digest for the given list only, otherwise the digests for all
44 lists are sent out. Multiple -l options may be given."""))
45 parser.add_option('-C', '--config',
46 help=_('Alternative configuration file to use'))
47 opts, args = parser.parse_args()
48 if args:
49 parser.print_help()
50 print >> sys.stderr, _('Unexpected arguments')
51 sys.exit(1)
52 return opts, args, parser
56 def main():
57 opts, args, parser = parseargs()
58 initialize(opts.config)
60 for listname in set(opts.listnames or config.list_manager.names):
61 mlist = MailList.MailList(listname, lock=False)
62 if mlist.digest_send_periodic:
63 mlist.Lock()
64 try:
65 try:
66 mlist.send_digest_now()
67 mlist.Save()
68 # We are unable to predict what exception may occur in digest
69 # processing and we don't want to lose the other digests, so
70 # we catch everything.
71 except Exception as errmsg:
72 print >> sys.stderr, \
73 'List: %s: problem processing %s:\n%s' % \
74 (listname,
75 os.path.join(mlist.data_path, 'digest.mbox'),
76 errmsg)
77 finally:
78 mlist.Unlock()
82 if __name__ == '__main__':
83 main()