diff.py: add binary support

This commit is contained in:
Emmanuel Garette 2022-03-29 16:24:52 +02:00
parent f979aa993d
commit d93404353e

View file

@ -42,12 +42,16 @@ type = "installe"
+++ +++
""") """)
for filename in FILES: for filename in FILES:
with open(join(OLD_DIR, filename[1:]), 'r') as ori:
ori_content = ori.readlines()
with open(join(NEW_DIR, filename[1:]), 'r') as new:
new_content = new.readlines()
print(f'- mise à jour du fichier {filename} :\n') print(f'- mise à jour du fichier {filename} :\n')
print('```diff') try:
for line in unified_diff(ori_content, new_content, fromfile=filename, tofile=filename): with open(join(OLD_DIR, filename[1:]), 'r') as ori:
print(line.rstrip()) ori_content = ori.readlines()
print('```') with open(join(NEW_DIR, filename[1:]), 'r') as new:
new_content = new.readlines()
except UnicodeDecodeError:
print('fichier binaire')
else:
print('```diff')
for line in unified_diff(ori_content, new_content, fromfile=filename, tofile=filename):
print(line.rstrip())
print('```')