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

          將下面的源碼存為 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

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


          網(wǎng)站導航:
           
           
          主站蜘蛛池模板: 万山特区| 哈巴河县| 资溪县| 阿拉善右旗| 定襄县| 宣威市| 屏东县| 增城市| 芦山县| 云阳县| 乐昌市| 鄂温| 米泉市| 香河县| 吉木萨尔县| 昌邑市| 永定县| 高碑店市| 林西县| 阜平县| 华亭县| 泸西县| 永定县| 高台县| 万盛区| 阿图什市| 济阳县| 水富县| 定州市| 全椒县| 宝兴县| 遵化市| 武宁县| 临武县| 静宁县| 吉隆县| 鄂温| 汉中市| 左权县| 晋城| 玛沁县|