[Checkins] SVN: zope.bugchecker/trunk/src/zope/bugchecker/bugchecker.py Add option to set SMTP port.

Tres Seaver tseaver at palladion.com
Tue Jun 22 11:01:23 EDT 2010


Log message for revision 113765:
  Add option to set SMTP port.
  
  Add short option flags for --mail-from, --mail-to.

Changed:
  U   zope.bugchecker/trunk/src/zope/bugchecker/bugchecker.py

-=-
Modified: zope.bugchecker/trunk/src/zope/bugchecker/bugchecker.py
===================================================================
--- zope.bugchecker/trunk/src/zope/bugchecker/bugchecker.py	2010-06-22 14:55:50 UTC (rev 113764)
+++ zope.bugchecker/trunk/src/zope/bugchecker/bugchecker.py	2010-06-22 15:01:22 UTC (rev 113765)
@@ -69,10 +69,12 @@
                      and "from" address. Host will default to localhost if
                      none is supplied here.
 
---mail-from          Address sending an e-mail report
+--mail-port, -p      Port number of the mail server.  Default is 25.
 
---mail-to            Address e-mail report will be sent to
+--mail-from, -f      Address sending an e-mail report
 
+--mail-to, -t        Address e-mail report will be sent to
+
 """
 
 import datetime
@@ -150,11 +152,11 @@
         if level <= self.verbose:
             print message
 
-def mail_it(mail_host, mail_from, mail_to, subject, report):
+def mail_it(mail_host, mail_port, mail_from, mail_to, subject, report):
     """Send report as e-mail"""
 
     mail = {}
-    mailserver = smtplib.SMTP(mail_host)
+    mailserver = smtplib.SMTP(mail_host, mail_port)
     msg = ('From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s' %
             (mail_from, mail_to, subject, report.getvalue()))
     mailserver.sendmail(mail_from, [mail_to], msg)
@@ -166,11 +168,12 @@
     states = []
     project_group = None
     sendmail = False
+    mail_port = 25
     mail_to = None
     mail_from = None
     try:
         options, args = getopt.gnu_getopt(sys.argv[1:],
-                                          '?hqvn:s:g:m',
+                                          '?hqvn:s:g:m:p::f:t:',
                                           ['help',
                                            'verbose',
                                            'quiet',
@@ -178,6 +181,7 @@
                                            'state=',
                                            'project-group=',
                                            'mail=',
+                                           'mail-port=',
                                            'mail-from=',
                                            'mail-to='
                                           ])
@@ -204,9 +208,11 @@
         elif k in ('-m', '--mail'):
             sendmail = True
             mail_host = v or 'localhost'
-        elif k == '--mail-to':
+        elif k in ('-p' '--mail-port'):
+            mail_port = int(v)
+        elif k in ('-t' '--mail-to'):
             mail_to = v
-        elif k == '--mail-from':
+        elif k in ('-f' '--mail-from'):
             mail_from = v
         else:
             print __doc__
@@ -267,7 +273,8 @@
         else:
             subject = ', '.join(projects)
         mail_it(mail_host, mail_from, mail_to, 
-                '%s : Total languishing bugs for %s:  %d' % (status, subject, total), report)
+                '%s : Total languishing bugs for %s:  %d'
+                    % (status, subject, total), report)
     if total > 0:
         sys.exit(-1)
 



More information about the checkins mailing list