-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileParserMozilla.py
More file actions
79 lines (58 loc) · 2.09 KB
/
FileParserMozilla.py
File metadata and controls
79 lines (58 loc) · 2.09 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
#This File Access all the text files in DATA folder and creates text files in "FILES" directory
#As input it takes the TC num
#Output : Creates two files 1. TC@num_condition.txt TC@num_function.txt
#The file contents as as follows: Header: #@TC@num
#LoopNum:Frequency
#Also create index.txt -> contains the mapping
#linename: linetxt
import os.path
import sys
#current testcase --> Obtained from console
testcasenum=sys.argv[1:]
testcasenum=map(str, testcasenum)
testcasenum=''.join(testcasenum)
parsedfileloc="./ParsedFiles"
filloc="./Data"
#Contains the location for all files in the Data Folder
filelocs=[]
for fil in os.listdir(filloc):
tmp=os.path.join(filloc, fil)
filelocs.append(tmp)
#For each file in the filelocs:
#1. Open the file
#2. Search for "if" and "else"
#3. Create the mappingfile TC@numLoopMapping.txt
#4. The mapping file has the entry -->linenum --- line to which it is allocated to
#3. Create a file TC@numloop.txt in parsedfileloc
#4. TC@numloop.txt has data like ---> linenum --> frequency
ifcounter=[]
elsecounter=[]
filenumdict={}
#Contain the mapping
linenumdict={}
#create the TC@nummap in ParsedFiles --> MApping file
filwrite=open(os.path.join(parsedfileloc, testcasenum+"map.txt"), "w+")
#Create the TC@num_Loop.txt
tcwrite=open(os.path.join(parsedfileloc, testcasenum+"_loop.txt"), "w+")
count=0
for fil in filelocs:
#Open the file
filhand=open(fil, "r+")
for i in filhand.readlines():
if(i!=""):
temp=i.strip(' ').split(":")
if("#" not in temp[0]):
if(str(temp[1]).find("for", 0,10)>0):
#temmp[1] -->line temp[0] --> frequency
print(temp[1] +" "+ temp[0])
filwrite.write(str(count)+":"+temp[1])
filwrite.write("\n")
tcwrite.write(str(count)+":"+temp[0])
tcwrite.write("\n")
filenumdict[temp[1]]=temp[0]
count=count+1
#i --:> line ### filenumdict[i] --> frequency of line
#Close the open file
filhand.close()
filwrite.close()
tcwrite.close()