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
|
import re
import dictdiffer
from tabulate import tabulate
file1 = "user.js"
file2 = "user.ark.js"
def create_dict(file):
dic = {}
with open(file) as f:
content = f.readlines()
content = [x.strip() for x in content]
for line in content:
if line.startswith("user_pref"):
results = re.match('user_pref\(\"(.+)\",\s*(.+)\s*\);', line)
setting_name = results[1]
setting_value = results[2]
dic[setting_name] = setting_value
return dic
def main():
dic1 = create_dict(file1)
dic2 = create_dict(file2)
currlist = []
done = False
print("Differences between {} and {}:".format(file1, file2))
for diff in list(dictdiffer.diff(dic1, dic2)):
if diff[0] == "change":
currlist.append([diff[1][0], diff[2][0], diff[2][1]])
if not done and diff[0] == "add":
done = True
print(tabulate(currlist, headers=['Name', file1, file2],
tablefmt='orgtbl'))
if diff[0] == "add":
print("Only in {}".format(file1))
print(tabulate(diff[1], headers=['Name', 'Setting'],
tablefmt='orgtbl'))
print("Only in {}".format(file2))
print(tabulate(diff[2], headers=['Name', 'Setting'],
tablefmt='orgtbl'))
if diff[0] == "remove":
print("Removed in {}".format(file1))
print(tabulate(diff[1], headers=['Name', 'Setting'],
tablefmt='orgtbl'))
print("Removed in {}".format(file2))
print(tabulate(diff[2], headers=['Name', 'Setting'],
tablefmt='orgtbl'))
if __name__ == '__main__':
main()
|