-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlog_compare.py
124 lines (89 loc) · 2.46 KB
/
log_compare.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
import hashlib
import csv
import os
import sys
class Log(object):
def __init__(self, f):
self.log_name = f
self.data = self.get_data(f)
self.log_dict = self.log_parser(self.data)
def get_data(self, f):
"""pulls a csv reader from the file"""
data = []
csvfile = open(f, 'rb')
reader = csv.reader(csvfile)
return reader
def log_parser(self, log):
"""parses the reader, and extracts the salient item data"""
self.log_dict = {}
for row in log:
key = os.path.join(row[4], row[5])
self.log_dict[key] = [row[4], row[5], row[8]]
return self.log_dict
class Tools(object):
def __init__(self):
pass
def compare_hashes(self, a, b):
"""returns the ans to does MD5 a == MD5 b"""
m = hashlib.md5()
m.update(a)
a_hash = m.hexdigest()
m = hashlib.md5()
m.update(b)
b_hash = m.hexdigest()
return a_hash == b_hash
class Checks(object):
def __init__(self, a, b):
self.a = a.log_dict
self.a_label = a.log_name
self.b = b.log_dict
self.b_label = b.log_name
self.all_checks()
def all_checks(self):
"""performs the item check by iterating through both lists per item looking for the item in the other list, and item delta"""
self.delta_check = None
for item, value, in self.a.items():
item_check = self.missing_check(item, self.b)
if item_check:
if value == self.b[item]:
pass
else:
print "'{}' has a different hash".format(item)
else:
print "'{}' is missing from '{}'".format(item, self.b_label)
print "Iteration 1 complete"
for item, value, in self.b.items():
item_check = self.missing_check(item, self.a)
if item_check:
if value == self.a[item]:
pass
else:
print "'{}' has a different hash".format(item)
else:
print "'{}' is missing from '{}'".format(item, self.a_label)
print "Iteration 2 complete"
def missing_check(self, item, my_dict):
"""returns the logic test if a is in list b"""
if item in my_dict.keys():
return True
else:
return False
def main(a, b):
tools = Tools()
log_a = Log(a)
log_b = Log(b)
checks = Checks(log_a, log_b)
if __name__ == '__main__':
######## editable block #########
"""Log file A location"""
log_a = r"tests\test_log_master.csv"
"""Log file B location"""
log_b = r"tests\test_log_all_bad_cases.csv"
#################################
if len(sys.argv) == 3:
try:
log_a = sys.argv[1]
log_b = sys.argv[2]
except:
quit("Too many, or not enough arguments")
main(log_a, log_b)