This repository was archived by the owner on Mar 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff-tool.py
More file actions
executable file
·78 lines (64 loc) · 1.84 KB
/
diff-tool.py
File metadata and controls
executable file
·78 lines (64 loc) · 1.84 KB
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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import re
import copy
class DiffTool:
def __init__(self):
self.pattern = re.compile("^[a-zA-Z0-9_]*:[a-zA-Z0-9_]*=")
def match(self, line):
return self.pattern.search(line)
def collect(self, file):
s = set()
while True:
line_raw = file.readline()
if not line_raw:
break
line = line_raw.rstrip()
if d.match(line):
s.add(line)
return s
class MakeDict:
"""
NAME
gui value
ter value
"""
def __init__(self):
pattern = re.compile(":")
self.split = pattern.split
self.d = dict()
def add_vars(self, myset, tag):
for line in myset:
key_value = self.split(line)
if len(key_value) > 2:
raise NotImplementedError
key = key_value[0]
if self.d.get(key):
self.d[key][tag] = key_value[1]
else:
temp = {"gui": " < empty >", "ter": " < empty >"}
temp[tag] = key_value[1]
self.d[key] = temp
if __name__ == "__main__":
gui = open("CMakeCache_gui.txt", "r")
ter = open("CMakeCache_terminal.txt", "r")
# gui = open("a.txt", "r")
# ter = open("b.txt", "r")
d = DiffTool()
gui_vars = d.collect(gui)
ter_vars = d.collect(ter)
# remove dup
for v in copy.copy(ter_vars):
if v in gui_vars:
gui_vars.remove(v)
ter_vars.remove(v)
# make dict
s = MakeDict()
s.add_vars(gui_vars, "gui")
s.add_vars(ter_vars, "ter")
# wirte file
res = open("result.txt", "w")
for k, v in s.d.items():
res.write("(ter) {}:{}\n".format(k, v["ter"]))
res.write("(gui) {}:{}\n\n".format(k, v["gui"]))
res.close()