scripts/gendiff.py: support diff options

This commit is contained in:
The MMGen Project 2024-10-08 12:55:58 +00:00
commit 7fbb50db92
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2

View file

@ -18,7 +18,8 @@ The cleaned source files are saved with the .clean extension.
import sys,re
from difflib import unified_diff
fns = sys.argv[1:]
fns = sys.argv[1:3]
diff_opts = sys.argv[4:] if sys.argv[3:4] == ['--'] else None
translate = {
'\r': None,
@ -55,7 +56,11 @@ cleaned_texts = [cleanup_file(fn) for fn in fns]
if len(fns) == 2:
# chunk headers have trailing newlines, hence the rstrip()
sys.stderr.write('Generating diff\n')
print(
f'diff a/{fns[0]} b/{fns[1]}\n' +
'\n'.join(a.rstrip() for a in unified_diff(*cleaned_texts,fromfile=f'a/{fns[0]}',tofile=f'b/{fns[1]}'))
)
if diff_opts:
from subprocess import run
run(['diff', '-u'] + [f'{fn}.clean' for fn in fns])
else:
print(
f'diff a/{fns[0]} b/{fns[1]}\n' +
'\n'.join(a.rstrip() for a in unified_diff(*cleaned_texts,fromfile=f'a/{fns[0]}',tofile=f'b/{fns[1]}'))
)