# This script is used to check for job fixes on given # codelines. A user may input one or two depot paths. # For example //depot/main/jam/... and //depot/rel1/jam/... # The fixes results for each path are stored in the depot # under the 'fixespath' directory. # Be sure and create the fixespath directory before running # the script for the first time. # If one path is input then the fixes for that path is output. # If two paths are input then the fixes for each path are listed # and the jobs in each path that do not appear in the other # are listed. # # Gerry Thompson Python Class Perforce Software 2002 # Version 1.0 import marshal, os, re, string, p4s p4path = 'p4' # Path to p4 executable fixespath = '//depot/versions/fixes/' # path to fixes file in depot admin = 'gerry+fixes@perforce.com' # My 'From' address for email to = 'gerry@perforce.com' # My email address p4 = p4path def showdiffs(alphaname, alphapath, betaname, betapath, secondcodeline): # List of jobs fixed in fist path: print 'Here are the jobs fixed in: '+ alphapath alist = os.popen(p4 + ' -G fstat '+ fixespath + alphaname, 'rb') dict = marshal.load(alist) apath = dict['clientFile'] for eachline in open(apath, 'r').readlines(): newlist = string.split(eachline, ) print newlist[0] print '\n' # List of jobs fixed in second path: if secondcodeline: print 'Here are the jobs fixed in: '+ betapath blist = os.popen(p4 + ' -G fstat '+ fixespath + betaname, 'rb') dict = marshal.load(blist) bpath = dict['clientFile'] for everyline in open(bpath, 'r').readlines(): newlist = string.split(everyline, ) print newlist[0] print '\n' # Show the diffs between the two fixes files. # This relies on p4 diff2 of two files submitted to a Perforce depot # that contain the names of the jobs for each codeline. alphalist = [] betalist = [] for aline in os.popen( p4 + ' diff2 '+ fixespath + alphaname + ' ' + fixespath + betaname, 'r').readlines(): alist = string.split(aline, ) if alist[0] == '<': alphalist.append(alist[1]) if alist[0] == '>': betalist.append(alist[1]) print 'These jobs are fixed in '+ alphapath + ' but not in '+ betapath number = len(alphalist) for count in range (0, number): print alphalist[count] print '\n' print 'These jobs are fixed in '+ betapath + ' but not in '+ alphapath number = len(betalist) for count in range (0, number): print betalist[count] def checkfiles(filename): oneline = os.popen(p4 + ' -s files '+ fixespath + filename, 'r').readline() check = string.split(oneline, ) if len(check) == 0: print 'An error has occured in p4fixed.py' else: if check[0] == 'error:': # The filename is a new fixes file. os.popen(p4 + ' add ' + fixespath + filename) else: os.popen(p4 + ' sync '+ fixespath + filename) os.popen(p4 + ' edit '+ fixespath + filename) # The filename exists. The file is opened using # the fixes path and the filename. def makefile(onename, onelist): checkfiles(onename) alist = os.popen(p4 + ' -G fstat '+ fixespath + onename, 'rb') dict = marshal.load(alist) path = dict['clientFile'] open(path, 'w').writelines(onelist) p4s.tryit(admin, to) def makelist(pathname): joblist = [] counter = 0 for aline in os.popen(p4 + ' fixes '+ pathname ,'r').readlines(): astring = string.split(aline, ) if counter == 0: joblist.append(astring[0]) joblist.append('\n') counter = counter + 2 else: if joblist[counter-2] != astring[0]: # This part elimates the same joblist.append(astring[0]) # jobname if fixed to multiple joblist.append('\n') # changelists in the same codeline. counter = counter + 2 return joblist def getfixes(namea, patha, nameb, pathb): counter = 0 joblista = [] joblistb = [] joblista = makelist(patha) makefile(namea, joblista) if pathb != '': twopaths = 1 joblistb = makelist(pathb) makefile(nameb, joblistb) showdiffs(namea, patha, nameb, pathb, twopaths) def getnames(): for lines in os.popen(p4 + ' files '+ fixespath + '...' , 'r').readlines(): # Less lines using a regular expression. #depotpath = string.split(lines, ) #filename = depotpath[0] #namewithrev = string.split(filename, fixespath) #nameonly = string.split(namewithrev[1], '#') #print nameonly[0] m = re.match('//(.+?)/(\w+?)#(.+)$', string.split(lines, )[0]) print m.group(2) def getpaths(): firstpath = '' firstfilename = '' secondpath = '' secondfilename = '' print '\n' print """ You can check the job fixes for a single codeline or two codelines. If you wish to see the fixes for a single codeline only press "enter" when prompted to the second fixes file name and second depot path. If two codelines are selected this script will also print the fixes in each codeline that do not appear in the other."""+'\n' print 'Here is a list of the fixes file names currently in use:' + '\n' getnames() print '\n' print 'Enter a file name for the first fixes file:' + '\n' firstfilename = raw_input() print """Enter a depot path for the first codeline. For example //depot/main/jam/...""" + '\n' firstpath = raw_input() print """Enter a file name for the second fixes file or "enter" to list the fixes for one path only:""" + '\n' secondfilename = raw_input() print """Enter a second depot path or "enter" to list the fixes for one codeline. For example //depot/rel1/jam/...""" + '\n' secondpath = raw_input() getfixes(firstfilename, firstpath, secondfilename, secondpath) if __name__ == '__main__': getpaths()