-
Notifications
You must be signed in to change notification settings - Fork 1
/
logextract.py
163 lines (141 loc) · 4.24 KB
/
logextract.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/python
#This python script can be used to generate a summary file would list all the successful, failure, skip and errors
import os
import re
import sys
failure_count, failure_msg = 0 , []
success_count, success_msg = 0 , []
skip_count, skip_msg = 0 , []
error_count, error_msg = 0, []
skip_flag = 0
if len(sys.argv)!=3:
print "./logextract.py jobID_path list_of_tests_path"
sys.exit()
logFile=sys.argv[1]
listFile=sys.argv[2]
l = logFile.split('/')
summaryFile = "Summary_"+l[len(l)-1]+".txt"
summaryFile = open(summaryFile, "w")
text = open(logFile,'r')
readSecondLine = []
for line in text:
if re.match("^failure:", line):
skip_flag = 0
#failure_count += 1
msg=str(line.split('[')[0]).split('failure: ')[1]
if msg.split(' ')[0] == 'setUpClass':
listText=open(listFile,'r')
temp=[]
for xline in listText:
if re.match(msg[msg.index('(')+1:msg.index(')')], xline):
temp.append("SetUp :"+xline)
failure_count += 1
failure_msg.append(temp)
listText.close()
else:
failure_msg.append(msg)
failure_count += 1
#failure_msg.append(str(line.split(' [ ')[0]).split('failure: ')[1])
if re.match("^successful:", line):
skip_flag = 0
success_count += 1
success_msg.append(str(line.split(' [ ')[0]).split('successful: ')[1])
if re.match("^skip:", line):
skip_flag = 1
#skip_count += 1
temp=[]
#skip_msg.append(str(line.split(' [ ')[0]).split('skip: ')[1])
msg= str(line.split('[')[0]).split('skip: ')[1]
if msg.split(' ')[0] == 'setUpClass':
listText=open(listFile,'r')
for xline in listText:
if re.match(msg[msg.index('(')+1:msg.index(')')], xline):
skip_msg.append("SetUp: "+xline)
skip_count += 1
listText.close()
else:
skip_msg.append(msg)
skip_count += 1
if re.match("^error:", line):
skip_flag = 0
error_count += 1
error_msg.append(str(line.split(' [ ')[0]).split('error: ')[1])
if re.match("^reason",line) and skip_flag == 1:
#tempMsg=' '
readSecondLine.append(1)
#if len(skip_msg)>1:
tempMsg = skip_msg[len(skip_msg)-1]
skip_msg.remove(tempMsg)
if len(readSecondLine) >= 1:
readSecondLine.append(1)
if len(readSecondLine) == 4:
skip_msg.append(tempMsg+" // reason :"+line)
readSecondLine = []
text.close()
print "Log Summary :"
summaryFile.write("Log Summary :\n")
print "Number of tests :",failure_count+success_count+skip_count
summaryFile.write("Number of tests : %d\n" %(failure_count+success_count+skip_count))
print "Fails :",failure_count
summaryFile.write("Fails : %d\n" %(failure_count))
print "Successful :",success_count
summaryFile.write("Successful :%d\n"%(success_count))
print "Errors :",error_count
summaryFile.write("Errors : %d\n" %(error_count))
print "skip :",skip_count
summaryFile.write("skip : %d\n"%(skip_count))
print "_"*150
summaryFile.write("_"*150)
print "Details :"
summaryFile.write("\nDetails :\n")
print "Failure Details :"
summaryFile.write("Failure Details :\n")
xcount = 1
for item in failure_msg:
if type(item)==list:
for element in item:
print "%d.\t%s"%(xcount,element)
string = "%d.\t%s\n"%(xcount,element)
summaryFile.write(string)
xcount+=1
else:
print "%d.\t%s"%(xcount,item)
string = "%d.\t%s\n"%(xcount,item)
summaryFile.write(string)
xcount += 1
print "_"*150
summaryFile.write("_"*150)
summaryFile.write("\n")
print "Skip Details :"
summaryFile.write("Skip Details :\n")
xcount = 1
for item in skip_msg:
print "%d.\t%s"%(xcount,item)
string = "%d.\t%s\n"%(xcount,item)
summaryFile.write(string)
xcount += 1
print "_"*150
summaryFile.write("_"*150)
summaryFile.write("\n")
print "Error Details :"
summaryFile.write("Error Details :\n")
xcount = 1
for item in error_msg:
print "%d.\t%s"%(xcount,item)
string = "%d.\t%s\n"%(xcount,item)
summaryFile.write(string)
xcount += 1
print "_"*150
summaryFile.write("_"*150)
summaryFile.write("\n")
print "Successful Details :"
summaryFile.write("Successful Details :\n")
xcount = 1
for item in success_msg:
#print "%d.\t%s"%(xcount,item)
string = "%d.\t%s\n"%(xcount,item)
summaryFile.write(string)
xcount += 1
print "_"*150
summaryFile.write("_"*150)
summaryFile.write("\n")