# This progam is used to automatically send email # when a changelist is sumbitted. # # Gerry Thompson Python Class Perforce Software 2002 # Version 1.0 import os, string, smtplib p4path = 'p4' # Path to p4 executable. mailhost = 'pop' # SMTP mail host name. p4 = p4path def showresults(user, client, server): oneline = os.popen(p4 + ' -p '+ server + ' changes -m1 -c '+ client + ' -u '+ user, 'r').readline() changeno = string.split(oneline, ) if changeno[6] == '*pending*': print 'Changelist '+ changeno[1] + ' is pending, please correct problem and sumbit.' themessage = 'Changelist '+ changeno[1] + ' is pending, please correct problem and sumbit.' +'\n'+'\n' else: themessage = 'Your default changelist has been submitted automatically.'+ '\n'+ '\n' for oneline in os.popen(p4+ ' describe -s '+ changeno[1], 'r').readlines(): themessage = themessage + oneline print '\n', themessage return themessage def sendmail(fromaddress, toaddress, username, clientname, servername): message = showresults(username, clientname, servername) from smtplib import SMTP fullmessage = 'From: '+ fromaddress + '\r\nTo: '+ toaddress +\ '\r\nSubject: ' + message server = SMTP(mailhost) # These two lines can be made into one. server.sendmail(fromaddress,toaddress, fullmessage) server.quit()