-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_duplicate_procs.py
More file actions
92 lines (77 loc) · 2.91 KB
/
find_duplicate_procs.py
File metadata and controls
92 lines (77 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python
"""
This utility file can be called as cvs commitinfo to go through the diff
and find the list of new tcl procs being committed and compare it with
the repository to detect the duplicate procs.
If duplicate proc detected, we can abort the commit.
"""
import sys, os, glob
import subprocess, re, itertools
import pdb
procToFile = dict()
def getNewProcsFromDiff(fileName, oldVer, newVer):
"""
1- Go through each line of diff between oldVer and newVer
2- find the list of proc in the diff and return it
"""
p = subprocess.Popen('cvs diff -r ' + newVer + ' -r ' + oldVer + ' '\
+ changedFile, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
match = re.search("> proc (\S+)", line)
if match:
procList = match.groups()
retval = p.wait()
return procList
def getProcsFromFile(filename):
"""
1- Go through each line in a given file.
2- Find the list of all proc defined and return the proc list
"""
procList = []
for i, line in enumerate(open(filename)):
match = re.search("^proc (\S+)", line)
if match:
tprocList = list(match.groups())
for procName in tprocList:
try:
procToFile[procName] = filename + " " + procToFile[procName]
except KeyError, e:
procToFile[procName] = filename
procList = procList + tprocList
#print "file " + filename + " len " + str(len(procList))
return procList
def getProcsFromRepo():
"""
1- Go through listOfDirs and in each dir find the list of tcl files.
"""
listOfDirs = ['/home/manid/wss/library']
procList = []
for testDir in listOfDirs:
for filename in glob.glob(testDir+'/*.tcl'):
procList = getProcsFromFile(filename)
for root, dirnames, files in os.walk(testDir):
for dirname in dirnames:
if dirname == "CVS":
continue
for filename in glob.glob(os.path.join(root, dirname)+'/*.tcl'):
procList = procList + getProcsFromFile(filename)
#print "procList " + str(procList) + " :END"
return procList
for arg in sys.argv[1:]:
#print "arg is " + arg
#changedFile, oldVer, newVer = arg.split(',')
#print "changedFile is " + changedFile
#print "oldVer is " + oldVer
#print "newVer is " + newVer
changedFile = arg
procsToTest = ['SGV', 'isStringEqual']
procsToCommit = getProcsFromFile(changedFile)
existingProcs = getProcsFromRepo()
#print str(procsToCommit) + "END+++"
#print str(existingProcs) + "END+++"
#for newProc in procsToTest:
for newProc in procsToCommit:
print "newPorc " + newProc
if newProc in existingProcs:
print "duplicate proc detected for " + newProc + " in " + str(procToFile[newProc])
failFlag = 1