-
Notifications
You must be signed in to change notification settings - Fork 0
/
genFixedFile.py
102 lines (93 loc) · 4.29 KB
/
genFixedFile.py
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
93
94
95
96
97
98
99
100
101
102
import os, shutil
import sys, getopt
import fileinput
import re
from collections import deque
import subprocess
import sys
def getDiffFiles(dir,difffile):
diffl = []
difflines = []
prev_file = ""
with open(dir+"/bugged-program.txtc",'w+') as bfile:
with open(dir+"/fixed-file.diffc",'w+') as ffile:
with open(difffile) as inf:
for line in inf:
if line.startswith("File"):
parts = re.split('\s+', line)
if len(parts) > 2: # if at least 2 parts/columns
diffl.append(parts[1])
prev_file = parts[1]
if not re.match(".*\.h",prev_file):
bfile.write(prev_file+"\n")
elif not re.match(".*\.h",prev_file):
if len(line) > 2:
ctype = line[0]
nline = line[1:]
if (ctype == "M"):
pparts = re.split('>', nline)
if len(pparts) > 1:
prevf = pparts[0]
prevc = pparts[1]
prevparts = re.split('~', prevf)
currparts = re.split('~', prevc)
if len(currparts) > 1:
starti = int(currparts[0])
curri = starti
endi = int(currparts[1])
while curri <= endi:
if(curri!=endi):
ffile.write(prev_file+","+str(curri)+"\n")
else:
ffile.write(prev_file+","+str(curri)+"\n")
curri = curri + 1
else:
ffile.write(prev_file+","+prevc+"\n")
elif (ctype == "+"):
pparts = re.split('>', nline)
if len(pparts) > 1:
prevf = pparts[0]
prevc = pparts[1]
prevparts = re.split('~', prevf)
currparts = re.split('~', prevc)
if len(currparts) > 1:
starti = int(currparts[0])
curri = starti
endi = int(currparts[1])
while curri <= endi:
if(curri!=endi):
ffile.write(prev_file+","+str(curri)+"\n")
else:
ffile.write(prev_file+","+ str(curri)+"\n")
curri = curri + 1
else:
ffile.write(prev_file+","+prevc+"\n")
with open(dir+"/fixed-file.diffc",'r') as cfile:
with open(dir+"/fixed-file.diff",'w+') as file:
for line in cfile:
if line.strip():
file.write(line)
with open(dir+"/bugged-program.txtc",'r') as cfile:
with open(dir+"/bugged-program.txt",'w+') as file:
for line in cfile:
if line.strip():
file.write(line)
def main(argv):
difffile=""
try:
opts, args = getopt.getopt(argv, "d:", ["dfile=", "rev="])
except getopt.GetoptError:
print 'test.py -d <difffile> -r <revision>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'test.py -s <difffile> -r <revision>'
sys.exit()
elif opt in ("-d", "--dfile"):
difffile = arg
print 'Input file is "'+difffile
dir = os.path.dirname(difffile)
print "Dir name is " + dir
getDiffFiles(dir,difffile)
if __name__ == "__main__":
main(sys.argv[1:])