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