areguera / rpms / mailman

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