-
Notifications
You must be signed in to change notification settings - Fork 21
/
checkdiffs.py
76 lines (67 loc) · 2.38 KB
/
checkdiffs.py
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
import sys
import os
from itertools import zip_longest
from glob import glob
def checkDiffs(path1, path2):
def diffFeature(f):
with open(f'{path1}/{f}.tf') as h:
eLines = (
h.readlines()
if f == 'otext' else
(d for d in h.readlines() if not d.startswith('@'))
)
with open(f'{path2}/{f}.tf') as h:
nLines = (
h.readlines()
if f == 'otext' else
(d for d in h.readlines() if not d.startswith('@'))
)
i = 0
equal = True
cutOff = 40
limit = 4
nUnequal = 0
for (e, n) in zip_longest(eLines, nLines, fillvalue='<empty>'):
i += 1
if e != n:
if nUnequal == 0:
print(
'differences{}'.format(
'' if f == 'otext' else ' after the metadata'
)
)
shortE = e[0:cutOff] + (' ...' if len(e) > cutOff else '')
shortN = n[0:cutOff] + (' ...' if len(n) > cutOff else '')
print('\tline {:>6} OLD -->{}<--'.format(i, shortE.rstrip('\n')))
print('\tline {:>6} NEW -->{}<--'.format(i, shortN.rstrip('\n')))
equal = False
nUnequal += 1
if nUnequal >= limit:
break
print('no changes' if equal else '')
print(f'Check differences between TF files in {path1} and {path2}')
files1 = glob(f'{path1}/*.tf')
files2 = glob(f'{path2}/*.tf')
features1 = {os.path.basename(os.path.splitext(f)[0]) for f in files1}
features2 = {os.path.basename(os.path.splitext(f)[0]) for f in files2}
addedOnes = features2 - features1
deletedOnes = features1 - features2
commonOnes = features2 & features1
if addedOnes:
print(f'\t{len(addedOnes)} features to add')
for f in sorted(addedOnes):
print(f'\t\t{f}')
else:
print(f'\tno features to add')
if deletedOnes:
print(f'\t{len(deletedOnes)} features to delete')
for f in sorted(deletedOnes):
print(f'\t\t{f}')
else:
print(f'\tno features to delete')
print(f'\t{len(commonOnes)} features in common')
for f in sorted(commonOnes):
print(f'{f}')
diffFeature(f)
print('Done')
checkDiffs(*sys.argv[1:3])