forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiffcalc.py
22 lines (18 loc) · 789 Bytes
/
diffcalc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from colors import logcolors
from difflib import ndiff
from utils import getMaxSpaces
def calcDiff(firstFile, secondFile):
# calculate raw diff
diff = ndiff(firstFile, secondFile)
# calculate unique lines in secondfile
deltainit = ''.join(x[2:] for x in diff if x.startswith('+ '))
# reformat the lines
deltainit = deltainit.split('\n')
maxspacesinit = getMaxSpaces(deltainit)
print(f'{logcolors.BOLD}CHANGED LINES ARE{logcolors.ENDC}\n',
f'{logcolors.BOLD}-{logcolors.ENDC}' * maxspacesinit)
for ele in deltainit:
print(f'{logcolors.SUCCESS} {str(ele.strip())} {logcolors.ENDC}',
' ' * (maxspacesinit - len(ele.strip())), '+')
print('', f'{logcolors.BOLD}-{logcolors.ENDC}' * maxspacesinit)
return deltainit