-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_nearby.py
More file actions
65 lines (56 loc) · 2.11 KB
/
simple_nearby.py
File metadata and controls
65 lines (56 loc) · 2.11 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
import csv
import sys
def main():
file=open('/Users/zhipengzhang/dataset-small.csv')
aimed_file=open('/Users/zhipengzhang/simpleset.csv','w')
csvwriter=csv.writer(aimed_file,delimiter='@')
csvwriter = csv.writer(aimed_file)
csv_format=csv.reader(file,delimiter='@')
csv.field_size_limit(sys.maxsize)
begin=False
x = 0
for record in csv_format:
if(begin):
id = record[0]
buggy_code = record[1].splitlines(keepends=False)
patched_code = record[2].splitlines(keepends=False)
index = eval(record[3]) #begin location list
removed = eval(record[4])
added=eval(record[5])
if(isinstance(index,list)):
for bug_index in range(len(index)):
before=index[bug_index]
after=before+removed[bug_index]
before-=5
after+=5
if(before<0):
before=0
if(after>=len(buggy_code)):
after=len(buggy_code)-1
print('Bug Location ',index[bug_index],' Bug End ',index[bug_index]+removed[bug_index],' scope ',[before,after])
elif(isinstance(index,int)):
before=index-5
if(before<0):
before=0
strbefore=''
for line in buggy_code[before:index]:
strbefore+=line+'\n'
strbug=''
for line in buggy_code[index:index+removed]:
strbug+=line+'\n'
print(strbug)
strpatch=''
for line in patched_code[index:index+added]:
strpatch+=line+'\n'
print(strbug+'\n\n\n\n\n\n')
if(strbug!=''):
csvwriter.writerow([id,strbefore,strbug,strpatch])
print(x)
x+=1
else:
begin=True
csvwriter.writerow(['id','before','buggy_code','patched_code'])
aimed_file.close()
file.close()
if __name__=='__main__':
main()