-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl18_read_deltas_lines.py
More file actions
63 lines (51 loc) · 1.62 KB
/
l18_read_deltas_lines.py
File metadata and controls
63 lines (51 loc) · 1.62 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
import difflib
from difflib import Differ
def writeToFile(fNameOut, aList):
""" Little helper to write a list of strings to a file,
with correct closing of the file too.
"""
fo = open(fNameOut, "w")
fo.writelines(aList)
fo.close()
fn = "C:/delta.txt"
f = open(fn, "r")
left, right = [], []
# split "deltas" file into a left and right part
for line in f:
line = line.rstrip("\n")
left.append(line[:53] + "\n")
right.append(line[56:] + "\n")
f.close()
writeToFile("C:/left.txt", left)
writeToFile("C:/right.txt", right)
d = Differ()
result = list(d.compare(left, right))
writeToFile("C:/diff.txt", result)
newleft, newright, newall = [], [], []
for line in result:
## write to left only lines that are in left!
if line[0] == "-":
newleft.append(line[2:])
## write to right only lines that are in right!
elif line[0] == "+":
newright.append(line[2:])
## write to "all" lines that are in both sides!
else:
newall.append(line[2:])
def convHexTxtToBytesFile(fnameIn, fnameOut):
hexlist = []
fi = open(fnameIn)
for line in fi:
line = line.rstrip("\n")
hexlist.extend(line.split())
fi.close()
fo = open(fnameOut, "wb")
charList = [chr(int(cHex, 16)) for cHex in hexlist]
fo.writelines(charList)
fo.close()
writeToFile("C:/in_left.txt", newleft)
writeToFile("C:/in_right.txt", newright)
writeToFile("C:/in_all.txt", newall)
convHexTxtToBytesFile("C:/in_left.txt", "C:/out_left.png")
convHexTxtToBytesFile("C:/in_right.txt", "C:/out_right.png")
convHexTxtToBytesFile("C:/in_all.txt", "C:/out_all.png")