comparison bin/sendnotificationmails.py @ 564:a61046da30a1

Check if config file exists and set destination of --config option to config_file
author Bjoern Ricks <bricks@intevation.de>
date Fri, 02 Sep 2011 10:25:59 +0000
parents a4efa91bc3b2
children 7de7869962ef
comparison
equal deleted inserted replaced
563:a4efa91bc3b2 564:a61046da30a1
7 # Read the file COPYING coming with the software for details. 7 # Read the file COPYING coming with the software for details.
8 8
9 """Send pending notification mails""" 9 """Send pending notification mails"""
10 10
11 import os 11 import os
12 import os.path
13 import sys
12 import smtplib 14 import smtplib
13 import email 15 import email
14 import email.Utils 16 import email.Utils
15 from optparse import OptionParser 17 from optparse import OptionParser
16 from ConfigParser import SafeConfigParser 18 from ConfigParser import SafeConfigParser
34 parser = OptionParser() 36 parser = OptionParser()
35 parser.set_defaults(config_file=os.path.join(treepkgcmd.topdir, 37 parser.set_defaults(config_file=os.path.join(treepkgcmd.topdir,
36 "notification.cfg")) 38 "notification.cfg"))
37 parser.add_option("--config", "--config-file", 39 parser.add_option("--config", "--config-file",
38 help=("The configuration file." 40 help=("The configuration file."
39 " Default notification.cfg")) 41 " Default notification.cfg"), dest="config_file")
40 return parser.parse_args() 42 return parser.parse_args()
41 43
42 44
43 def send_mail(config, raw_message): 45 def send_mail(config, raw_message):
44 msg = email.message_from_string(raw_message) 46 msg = email.message_from_string(raw_message)
71 send_mail(config, template % values) 73 send_mail(config, template % values)
72 74
73 75
74 def main(): 76 def main():
75 options, args = parse_commandline() 77 options, args = parse_commandline()
78 if not os.path.exists(options.config_file):
79 print sys.stderr >> , "File not found: %s" % options.config_file
80 sys.exit(1)
76 send_notification_mails(options.config_file) 81 send_notification_mails(options.config_file)
77 82
78 main() 83 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)