-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiffcolor.py
More file actions
executable file
·53 lines (36 loc) · 985 Bytes
/
diffcolor.py
File metadata and controls
executable file
·53 lines (36 loc) · 985 Bytes
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
#!/usr/bin/python
import argparse
parser = argparse.ArgumentParser(description='Compare two files and print the difference in red')
parser.add_argument('-o', required=True, help="Old text file")
parser.add_argument('-n', required=True, help="New text file")
args = parser.parse_args()
redfg='\033[31m'
redbg='\033[41m'
reset='\033[0m'
f=file(args.o)
oldtext=f.read()
f.close()
f=file(args.n)
newtext=f.read()
f.close()
olines=oldtext.split("\n")
nlines=newtext.split("\n")
for [oldline, newline] in zip(olines, nlines):
pline = ""
ochars=list(oldline)
nchars=list(newline)
m = min(len(ochars), len(nchars))
if (len(ochars) < len(nchars)):
newbigger=True
else:
newbigger=False
for a in range(0, m):
if (ochars[a]==nchars[a]):
pline += ochars[a]
else:
pline += redfg + nchars[a] + reset
if (newbigger):
pline+= redfg + "".join(nchars[m:]) + reset
else:
pline+=redbg + "".join(ochars[m:]) + reset
print pline