Java 企業應用
          不要溫柔的走入那個良夜

          將下面的源碼存為 send_notifications.py ,然后 用python send_notifications.py XX XX 使用。

          import
           smtplib
          import time
          import sys
          import os, shutil

          print "Usage:python", sys.argv[0], "[recipient](1..n) reports_dir"
          print "Example:python", sys.argv[0], " wilson@ex.com jake@ex.com /opt/reports"

          # constants
          fromaddr = "*****@gmail.com"
          password 
          = ''

          def timestamp():
              ISOTIMEFORMAT 
          = "%Y-%m-%d-%X"
              
          return str(time.strftime(ISOTIMEFORMAT))

          def send_mail(fromaddr, password, toaddrs, reports_dir):
              server 
          = smtplib.SMTP('smtp.gmail.com:587')
              server.ehlo()
              server.starttls()
              server.login(fromaddr, password)
              
          for x in toaddrs:server.sendmail(fromaddr, x, mail_content(x, reports_dir))
              server.quit()
              
          def read_surefire_report(reports_dir):
              report_lines 
          = []
              
          if os.path.isdir(reports_dir):
                  reports 
          = os.listdir(reports_dir)
                  
          for x in reports:
                      
          if x.endswith(".txt"):
                          with open(
          "%s/%s" % (reports_dir, x), "r") as f:
                              report_lines.extend(f.readlines())
              
          return report_lines

          def mail_content(recipient, reports_dir):
              recipient_name 
          = recipient.split("@")[0]
              site_endpoint 
          = "http://***********:8080/sce-deck"
              mail_body 
          = [
                
          "From: Decker<%s>" % fromaddr,
                
          "To: %s<%s>" % (recipient_name, recipient),
                
          "Subject: SCE-DECK-REPORT-" + timestamp(),
                
          "",
                
          "hi,%s" % recipient_name,
                
          "",
                
          "Junit Testcase %s/surefire-report.html" % site_endpoint,
                
          "Test Coverage  %s/cobertura/index.html" % site_endpoint,
                
          "Tag List %s/taglist.html" % site_endpoint,
                
          "Duplicate code detection %s/cpd.html" % site_endpoint ,
                
          "Verification of coding rules %s/pmd.html" % site_endpoint,
                
          "",
                
          "Test Result Quick View:"
                ]
              mail_body.extend(read_surefire_report(reports_dir))
              mail_body.extend(
                [ 
          "What's more ?",
                
          "Project,Dependencies,javadoc ,test javadoc ,Test Source Xref, Source Xref ",
                site_endpoint,
                
          ""
                ])
              
          return "\r\n".join(mail_body)

          if __name__ == "__main__":
              recipients 
          = sys.argv[1:-1:] if len(sys.argv[:]) > 2 else [] 
              reports_dir 
          = sys.argv[-1]
              
          if len(recipients) > 0:
                  
          print ">> Send mail to "",".join(recipients)
                  
          print ">> Reports - ", reports_dir
                  send_mail(fromaddr, password, recipients, reports_dir)
              
          else:
                  
          print ">> No boby is in the recipients."                                                                                                                                                                                                                                                                                                       



          posted on 2013-07-29 09:22 cpegtop 閱讀(178) 評論(0)  編輯  收藏 所屬分類: Python

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
           
          主站蜘蛛池模板: 娄底市| 客服| 宁夏| 屏边| 伊宁市| 云龙县| 萝北县| 华容县| 宽甸| 辽宁省| 金溪县| 会昌县| 泸溪县| 郯城县| 新丰县| 铅山县| 吉安县| 乌兰浩特市| 永川市| 屯昌县| 芜湖县| 藁城市| 文昌市| 绩溪县| 合作市| 耒阳市| 正镶白旗| 壶关县| 文昌市| 左云县| 监利县| 邯郸县| 金坛市| 德庆县| 双柏县| 博客| 交口县| 泸溪县| 通城县| 临桂县| 吉首市|