#!/usr/local/bin/python # filehistorymetrics.py # Written 2/2000 by Joshua Grigonis # list files in label. Show changes in file between builds import sys, string, re, os, makemetricsfiles debug = 0 if len (sys.argv) == 5: if sys.argv[4] == "2": debug = 2 if sys.argv[4] == "1": debug = 1 file_pattern = re.compile ("//.*#[0-9]* - ", re.IGNORECASE) change_pattern = re.compile ("Change [0-9]* ", re.IGNORECASE) summary_pattern = re.compile ("====.*==== content", re.IGNORECASE) ############################################################################### def print_summary (file2, file1): if debug >= 1: print "print_summary starting" print "file1 = " + file1 print "file2 = " + file2 printit = 0 print "\n" for eachline in os.popen ('p4 diff2 -ds \"' + file2 + "\" \"" + file1 + "\"").readlines(): if printit > 0: print eachline, printit = printit - 1 x = summary_pattern.match (eachline) if x != None: #string = x.group() printit = 3 if debug >= 1: print "print_summary exiting" ############################################################################### # def get_change_number (line, changeno, rev, filename): if debug >= 1: print "get_change_number starting" print "line = " + line print "changeno = " + str(changeno) print "rev = " + str(rev) w = change_pattern.match(line) somestring = w.group() printit = 0 for aline in os.popen ('p4 change -o ' + somestring[7:]).readlines(): revnum = rev - changeno revnumstr = "" revnumstr = revnumstr + str (revnum) revnum2 = rev - changeno - 1 revnumstr2 = "" revnumstr2 = revnumstr2 + str (revnum2) if debug >= 1: print aline if printit == 1: print "Revision: " + revnumstr print "Change: " + somestring[7:] print "\n" print "Description: " + aline[1:], file1 = filename + "#" + revnumstr file2 = filename + "#" + revnumstr2 if revnum > 0 and revnum2 > 0: print_summary (file2, file1) #print_summary (somestring[7:]) printit = 0 z = string.find(aline,"Description:") if z == 0: printit = 1 u = string.find(aline, "User:") if u == 0: print print aline, if debug >= 2: print somestring[7:] if debug >= 1: print "get_change_number exiting" ############################################################################### # rev is in the form "#xx" Where xx is a digit representing the version number # line is a full line from a p4 files command e.g.: # //depot/blah/blah/file.ext#xx - edit change 1234 (text) # rev is the revision of the file under newer label # line is from previous label def comp_ver_number (line, rev): if debug >= 1: print "comp_ver_number starting" x = file_pattern.match(line) thestring = x.group() pound = string.find (thestring, '#') space = string.find (thestring, ' ', pound) thisrev = thestring[pound:space] # if the file changed between labels if thisrev != rev: # get the revisions as integers rev1 = string.atoi(rev[1:]) rev2 = string.atoi(thisrev[1:]) # numchanges = rev1 - rev2 changeno = 0 if debug >=2: print thestring[:pound] print rev1 print rev2 y = file_pattern.match(line) astring = y.group() #print astring[:-3] thepound = string.find (astring, '#') thefile = astring [:thepound] newfile = thefile + rev # if debug >= 2: print "newfile = " + newfile print "now calling for aline...." print 'p4 changes \"' + newfile + '\"' for aline in os.popen ('p4 changes \"' + newfile + '\"').readlines(): numchanges = numchanges - 1 if numchanges >= 0: get_change_number (aline, changeno, rev1, thestring[:pound]) changeno = changeno + 1 if debug >= 2: print "thisrev = " + thisrev print "rev = " + rev print "comp_ver_number exiting" ############################################################################### def print_rev_history(file, rev): if debug >= 1: print "print_rev_history" print "file = " + file print "rev = " + rev found = 0 # for every line the files list for previous label for i in range (0, len(lines)): if found == 0: x = string.find (lines[i],file) if debug >=2: print "x = " print x print "found = " print found # we found that file in the temp file if x != -1: found = 1 # need to see if versions are diff, if so print the changes comp_ver_number (lines[i], rev) if debug >= 1: print "DEBUGGING " + lines[i] # file must have been added between builds # This part needs to be completed still if found != 1: if debug >= 1: print "DEBUGGING added file" rev1 = string.atoi(rev[1:]) changeno = 0 for aline in os.popen ('p4 changes ' + file).readlines(): get_change_number (aline, changeno, rev1, file) changeno = changeno + 1 ################################################################################# def print_file_info(): for line in os.popen ('p4' + ' files @' + sys.argv[3], 'r').readlines(): x = file_pattern.match(line) thestring = x.group() print "=====================================================" pound = string.find (thestring, '#') print "File: " + thestring[0:pound] space = string.find (thestring, ' ', pound) print "Revision: " + thestring[pound:space] if debug >= 1: print "Now calling print_rev_history (thestring[0:pound], thestring[pound:space])" print "print_rev_history (" + thestring[0:pound] + "," + thestring[pound:space] + ")" print_rev_history (thestring[0:pound], thestring[pound:space]) print "=====================================================" ################################################################################## if len (sys.argv) < 4: print "This script was called incorrectly" print "USAGE:" print "\t" + sys.argv[0] + " " sys.exit(1) made = 0 if not os.path.isfile (sys.argv[2] + '.label'): made = 1 makemetricsfiles.createlabel ('//depot/...', sys.argv[2], sys.argv[3]) try: file = open (sys.argv[2] + '.label', "r") except: print "Error opening file" + sys.argv[2] + '.label' sys.exit(1) lines = file.readlines() if debug>=2: print "DEBUGGING" print lines file.close() print_file_info() if made == 1: os.remove (sys.argv[2] + '.label') os.remove (sys.argv[3] + '.label')