areguera / rpms / mailman

Forked from rpms/mailman 4 years ago
Clone

Blame SOURCES/mailman-crontab-edit

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