areguera / rpms / mailman

Forked from rpms/mailman 4 years ago
Clone

Blame SOURCES/mailman-crontab-edit

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