# This progam is used to automatically version jobs. # Jobs are created or edited and submitted as versioned # files in your Perforce depot. # # New jobs are submitted to the jobpath directory in # the Perforce depot. Be sure and create the directory # before running the script for the first time. # # Gerry Thompson Python Class Perforce Software 2002 # Version 1.0 import marshal, os, string, p4s p4path = 'p4' # Path to p4 executable. jobpath = '//depot/versions/jobs/' # Path to job files in depot admin = 'gerry+jobs@perforce.com' # My 'From' address for email. to = 'gerry@perforce.com' # My email address. p4 = p4path def checkjob(ajob): oneline = os.popen(p4 + ' -s files '+ jobpath + ajob, 'r').readline() check = string.split(oneline, ) if len(check) == 0: print 'An error has occured in p4job.py' else: if check[0] == 'error:': # The jobname is a new job. os.popen(p4 + ' add ' + jobpath + ajob) else: os.popen(p4 + ' sync '+ jobpath + ajob) os.popen(p4 + ' edit '+ jobpath + ajob) # The jobname is an existing job. The file is opened using # the depot path and the job name. def makefile(job): checkjob(job) newline = [] for aline in os.popen(p4 + ' job -o '+ job, 'r').readlines(): if aline[0] != '#': if aline[0] != '\n': newline.append(aline) alist = os.popen(p4 + ' -G fstat //...' + job, 'rb') dict = marshal.load(alist) path = dict['clientFile'] open(path, 'w').writelines(newline) p4s.tryit(admin, to) def getjob(jobname): if jobname == '': command = ' job' else: command = ' job '+ jobname for line in os.popen(p4 + command ,'r').readlines(): astring = string.split(line, ) newjob = astring[1] makefile(newjob)