-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_validator.py
33 lines (29 loc) · 1.11 KB
/
log_validator.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
def validate():
f = open("log.txt", "r")
lines = f.readlines()
requests = []
grants = []
releases = []
for line in lines:
if ("[R] Request" in line):
requests.append(int(line.split("-")[1]))
continue
if ("[S] Grant" in line):
if (len(grants) != len(releases)):
print(line)
print(len(grants))
print(len(releases))
raise Exception("Invalid log file: invalid grants and releases sequence")
grants.append(int(line.split("-")[1]))
continue
if ("[R] Release" in line):
if (len(releases) != len(grants) - 1):
raise Exception("Invalid log file: invalid grants and releases sequence")
releases.append(int(line.split("-")[1]))
continue
for i in range(len(requests)):
if (requests[i] != grants[i] or grants[i] != releases[i]):
raise Exception("Invalid log file: invalid grants and releases sequence")
print("Log file was successfully validated")
if __name__ == "__main__":
validate()