[Checkins] SVN: z3c.testsummarizer/trunk/ Read configuration from a config file
Wolfgang Schnerring
wosc at wosc.de
Thu Mar 31 09:10:05 EDT 2011
Log message for revision 121174:
Read configuration from a config file
Changed:
U z3c.testsummarizer/trunk/README.txt
U z3c.testsummarizer/trunk/src/z3c/testsummarizer/main.py
-=-
Modified: z3c.testsummarizer/trunk/README.txt
===================================================================
--- z3c.testsummarizer/trunk/README.txt 2011-03-31 10:08:00 UTC (rev 121173)
+++ z3c.testsummarizer/trunk/README.txt 2011-03-31 13:10:04 UTC (rev 121174)
@@ -4,3 +4,14 @@
Script that checks a pipermail archive for recent messages, parses them
according to a test result format and creates a summary.
+
+To use, write a configuration file like this::
+
+ [testsummarizer]
+ archive_url = https://mail.zope.org/pipermail/zope-tests/
+ listname = zope-tests
+ from = Zope tests summarizer <noreply at localhost>
+ to = user at localhost
+ smtpserver = localhost
+
+and then call ``test-summarizer example.ini``.
\ No newline at end of file
Modified: z3c.testsummarizer/trunk/src/z3c/testsummarizer/main.py
===================================================================
--- z3c.testsummarizer/trunk/src/z3c/testsummarizer/main.py 2011-03-31 10:08:00 UTC (rev 121173)
+++ z3c.testsummarizer/trunk/src/z3c/testsummarizer/main.py 2011-03-31 13:10:04 UTC (rev 121174)
@@ -15,6 +15,7 @@
"""
from email.Utils import parseaddr
+import ConfigParser
import datetime
import getopt
import pkg_resources
@@ -24,15 +25,6 @@
import z3c.testsummarizer.format
-# Settings used by the script. You'll want to customize some of these.
-archive_url = 'https://mail.zope.org/pipermail/zope-tests/'
-listname = 'zope-tests'
-
-mailfrom = 'Zope tests summarizer <ct+zopetests at gocept.com>'
-mailto = 'zope-dev list <zope-dev at zope.org>'
-smtpserver = 'localhost'
-
-
def create_report(archive_url, listname, date):
yesterday = date - datetime.timedelta(days=1)
archive = z3c.testsummarizer.archive.Archive(archive_url)
@@ -59,36 +51,43 @@
"""Get the list of URLs, get the appropriate messages, compose an email,
send it to the mailing list.
"""
- usage = 'Usage: test-summarizer [-T YYYY-mm-dd]'
- selected_date = None
+ usage = 'Usage: test-summarizer [-T YYYY-mm-dd] configfile'
+ date = None
try:
- options, arg = getopt.getopt(sys.argv, 'hT:')
+ options, args = getopt.getopt(sys.argv, 'hT:')
except getopt.GetoptError, e:
err_exit('%s\n%s' % (e.msg, usage))
for name, value in options:
if name == '-T':
- selected_date = value.strip()
+ date = value.strip()
elif name == '-h':
err_exit(usage, 0)
else:
err_exit(usage)
- # All dates used are naive dates (no explicit tz).
- if selected_date:
- date = datetime.datetime.strptime(selected_date, '%Y-%m-%d')
+ if len(args) != 2:
+ err_exit(usage)
+
+ config = ConfigParser.ConfigParser()
+ config.readfp(open(args[1]))
+ config = dict(config.items('testsummarizer'))
+
+ if date:
+ date = datetime.datetime.strptime(date, '%Y-%m-%d')
else:
date = datetime.datetime.utcnow().replace(second=0, microsecond=0)
- subject, body = create_report(archive_url, listname, date)
+ subject, body = create_report(
+ config['archive_url'], config['listname'], date)
body = "From: %s\nTo: %s\nSubject: %s\n\n%s" % (
- mailfrom, mailto, subject, body)
+ config['from'], config['to'], subject, body)
- fromname, fromaddr = parseaddr(mailfrom)
- toname, toaddr = parseaddr(mailto)
+ fromname, fromaddr = parseaddr(config['from'])
+ toname, toaddr = parseaddr(config['to'])
- s = smtplib.SMTP(smtpserver, 25)
+ s = smtplib.SMTP(config['smtpserver'], 25)
s.sendmail(fromaddr, toaddr, body)
s.quit()
More information about the checkins
mailing list