-
Notifications
You must be signed in to change notification settings - Fork 0
/
logparser.py
40 lines (34 loc) · 1.09 KB
/
logparser.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
#!/usr/bin/env python
"""Description: this file automatically parses a lof for patterns and prints it. for use in linux environment"""
import sys
__Author__ = "Adam Szablya"
__date__ = "8/30/2016"
__version__ = "1.0"
FP = {"fail": 0, "pass": 0}
INDEXOF = []
def get_log():
if len(sys.argv) < 2:
with open("./fubar.log") as file:
data = file.readlines()
else:
with open(sys.argv[1]) as file:
data = file.readlines()
return data
def parse_log(input):
for line in input:
if "start pattern" in line:
INDEXOF.append(input.index("start pattern"))
if "end pattern" in line:
INDEXOF.append(input.index("end pattern"))
if "Result: Fail" in line:
FP["fail"] += 1
elif "Results: Pass" in line:
FP["Pass"] += 1
for i in range(INDEXOF[0], INDEXOF[1]):
print(input[i])
if __name__ == "__main__":
log = get_log()
parse_log(log)
print("Number of pass and fails:\n")
print("PASS: "+FP["Pass"]+"\n")
print("FAIL" + FP["Fail"])