Blame SOURCES/mailman-crontab-edit

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