Blame SOURCES/mailman-crontab-edit

5c2a97
#!/usr/bin/python2
5c2a97
5c2a97
# This script inserts the mailman user name into the crontab entries after
5c2a97
# the 5 time/date fields so that it can be installed under /etc/cron.d
5c2a97
#
5c2a97
# usage: mailman-crontab-edit [-s src_file] [-u mailman_user] [-d dst_file]
5c2a97
# src_file defaults to stdin
5c2a97
# mailman_user defaults to mailman
5c2a97
# dst_file defaults to stdout
5c2a97
5c2a97
import sys, re, getopt
5c2a97
5c2a97
srcFile = None
5c2a97
dstFile = None
5c2a97
mmUser = None
5c2a97
5c2a97
opts, args = getopt.getopt(sys.argv[1:], "s:d:u:")
5c2a97
for o, a in opts:
5c2a97
    if o == "-s":
5c2a97
        srcFile = a
5c2a97
    if o == "-d":
5c2a97
        dstFile = a
5c2a97
    if o == "-u":
5c2a97
        mmUser = a
5c2a97
5c2a97
if srcFile:
5c2a97
    inFD = open(srcFile)
5c2a97
else:
5c2a97
    inFD = sys.stdin
5c2a97
5c2a97
if dstFile:
5c2a97
    outFD = open(dstFile, mode='w')
5c2a97
else:
5c2a97
    outFD = sys.stdout
5c2a97
5c2a97
if not mmUser:
5c2a97
    mmUser = "mailman"
5c2a97
5c2a97
comment_re = re.compile(r'^\s*#')
5c2a97
time_date_re = re.compile(r'(^\s*(\S+\s+){5,5})')
5c2a97
5c2a97
for line in inFD:
5c2a97
    if not comment_re.search(line):
5c2a97
        match = time_date_re.search(line)
5c2a97
        if match:
5c2a97
            line = time_date_re.sub(r'\1 %s ' % mmUser, line)
5c2a97
    print >>outFD, line,