source: branches/testScripts/NBemail.py @ 651

Last change on this file since 651 was 642, checked in by jpfasano, 12 years ago

Osi's unitTest is now considered a success if Sym completes 89 out of 90 netlib testcases

  • Property svn:executable set to *
File size: 4.0 KB
Line 
1#! /usr/bin/env python
2
3import os
4import sys
5from socket import gethostname
6import smtplib
7
8import NBuserConfig
9import NBprojectConfig
10import NBlogMessages
11
12#------------------------------------------------------------------------
13#
14# This file contains the functions that deal with email
15#
16#------------------------------------------------------------------------
17
18#------------------------------------------------------------------------
19# Send email typically about an error.
20#  project: coin project name
21#  cmd: command being exucuted. perhaps: "svn update", "./configure",
22#       "make".
23#  cmdMsgs: the messages generated by cmd.  This will typically contain
24#       errors issued by cmd.
25#------------------------------------------------------------------------
26def sendCmdMsgs(project,cmdMsgs,cmd):
27  curDir = os.getcwd()
28 
29  toAddrs = [unscrambleAddress(NBuserConfig.MY_EMAIL_ADDR)]
30  if NBprojectConfig.PROJECT_EMAIL_ADDRS.has_key(project) \
31     and \
32     NBuserConfig.SEND_MAIL_TO_PROJECT_MANAGER:
33    scrambledEmailAddress=NBprojectConfig.PROJECT_EMAIL_ADDRS[project]
34    unscrambledEmailAddress=unscrambleAddress(scrambledEmailAddress)
35    toAddrs.append(unscrambledEmailAddress)
36
37  subject = project + " problem when running '" + cmd +"'"
38
39  emailMsg  = "'" + cmd + "' from directory " + curDir + " failed.\n\n"
40
41  emailMsg += "Operating System: "+sys.platform+" "+os.name+"\n"
42  emailMsg += "Host name: "+gethostname()+"\n"
43
44  if os.environ.has_key("PROCESSOR_IDENTIFIER") :
45    emailMsg += "Processor: "+os.environ["PROCESSOR_IDENTIFIER"]+"\n"
46                                         
47  if os.environ.has_key("NUMBER_OF_PROCESSORS") :
48    emailMsg += "Number of processors: "+os.environ["NUMBER_OF_PROCESSORS"]+"\n"
49   
50  if os.environ.has_key("PATH") :
51    emailMsg += "PATH: "+os.environ["PATH"]+"\n"
52
53  if cmdMsgs.has_key('make test') :
54    emailMsg += "\n\n'make test' problem:\n"
55    emailMsg += cmdMsgs['make test']
56    emailMsg += "\n" 
57  if cmdMsgs.has_key('unitTest') :
58    emailMsg += "\n\nDetected problem:\n"
59    emailMsg += cmdMsgs['unitTest']
60    emailMsg += "\n" 
61
62  emailMsg +="\n"
63
64  emailMsg += "stderr messages are:\n" 
65  emailMsg += cmdMsgs['stderr']
66  emailMsg += "\n\nstdout messages are:\n"
67  emailMsg += cmdMsgs['stdout']
68  if cmdMsgs.has_key('config.log') :
69    emailMsg += "\n\nconfig.log messages are:\n"
70    emailMsg += cmdMsgs['config.log']
71
72  send(toAddrs,subject,emailMsg)
73  NBlogMessages.writeMessage( "  email sent regarding "+project+" running '"+cmd+"'" )
74
75#------------------------------------------------------------------------
76# Send email
77#------------------------------------------------------------------------
78def send(toAddrs,subject,message):
79
80  sender = unscrambleAddress(NBuserConfig.SENDER_EMAIL_ADDR) 
81  msgWHeader = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
82       % (sender, ", ".join(toAddrs), subject))
83  msgWHeader += message
84 
85  # Get smpt server password
86  if os.path.isfile(NBuserConfig.SMTP_PASSWORD_FILENAME) :
87    pwFilePtr = open(NBuserConfig.SMTP_PASSWORD_FILENAME,'r')
88    smtppass  = pwFilePtr.read().strip()
89    #print smtppass
90    pwFilePtr.close()
91  else :
92    NBlogMessages.writeMessage( "Failure reading pwFileName=" + NBuserConfig.SMTP_PASSWORD_FILENAME )
93    sys.exit(1)
94   
95  session = smtplib.SMTP(NBuserConfig.SMTP_SERVER_NAME,NBuserConfig.SMTP_SERVER_PORT)
96  #session.set_debuglevel(1)
97  if NBuserConfig.SMTP_SSL_SERVER==1 :
98    session.ehlo('x')
99    session.starttls()
100    session.ehlo('x') 
101  session.login(unscrambleAddress(NBuserConfig.SMTP_USER_NAME),smtppass)
102
103  rc = session.sendmail(sender,toAddrs,msgWHeader)
104  if rc!={} :
105    NBlogMessages.writeMessage( 'session.sendmail rc='  )
106    NBlogMessages.writeMessage( rc )
107  session.quit()
108
109#------------------------------------------------------------------------
110# Decrypt email address
111#------------------------------------------------------------------------
112def unscrambleAddress( scrambledEmailAddress ) :
113  retVal = scrambledEmailAddress
114  retVal = retVal.replace(' _AT_ ','@')
115  retVal = retVal.replace(' _DOT_ ','.')
116  return retVal
117
Note: See TracBrowser for help on using the repository browser.