# This progam is used to automatically create a client specification. # # Gerry Thompson Python Class Perforce Software 2002 # Version 1.0 import os, string, smtplib p4port = 'localhost:1666' # This is a Perforce server. p4user = 'bruno' # Perforce user name to use. p4path = 'p4' # Path to p4 executable. admin = 'gerry+admin@perforce.com' # My 'From' address for email. to = 'gerry@perforce.com' # My email address. mailhost = 'pop' # SMTP mail host name. p4 = p4path + ' -u'+ p4user + ' -p' + p4port def sendmail(fromaddress, toaddress, message): 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() def makemessage(client,root,host): message = 'New client "'+ client +'" with root "' + root + '" at "'+ host + '" has been created.' + '\n' + '\n' for aline in os.popen(p4 + ' client -o ' + client,'r').readlines(): if aline[0] != '#': if aline[0] != '\n': # Do not include comments or spaces. message = message + aline print message sendmail(admin, to, message) def makespec(newclient,newroot,newhost): newspec = [] astring = ' ' indent = 0 view = 0 for aline in os.popen(p4 + ' client -o ','r').readlines(): list = string.split(aline, ) if len(list) > 0: if list[0] == 'Client:': tempclient = list[1] list[1] = newclient if list[0] == 'Host:': list[1] = newhost if list[0] == 'Root:': list[1] = newroot indent = 0 if indent == 1: list[0] = astring + list[0] if view == 1: list[1] = string.replace(list[1], tempclient, newclient) if list[0] == 'Description:': indent = 1 if list[0] == 'View:': indent = 1 view = 1 aline = string.join(list, ) + '\n' newspec.append(aline) os.popen(p4 + ' client -i ', 'w').writelines(newspec) makemessage(newclient,newroot,newhost) def getinfo(): print ('This command will create a new client specification.'), '\n' print ('Please input client name, client root, and'), '\n' print ('client host computer name for the client specification.'), '\n' nclient = raw_input('Client name: ') nroot = raw_input('Client root: ') nhost = raw_input('Client host computer name: ') makespec(nclient,nroot,nhost) return nclient if __name__ == '__main__': # This keeps the module from being launched automatically # when it is imported. getinfo()