1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-19 15:43:45 +02:00
RPGnotes/utils/diff.py
2023-08-06 19:21:33 +02:00

29 lines
912 B
Python

import subprocess
import sys
from difflib import Differ
from tempfile import NamedTemporaryFile
def print_diff_call(str1: str, str2: str, title: str) -> None:
title = title.replace("/", "")
with NamedTemporaryFile(delete=True, mode="w", suffix=title) as tmp1:
with NamedTemporaryFile(delete=True, mode="w", suffix=title) as tmp2:
tmp1.write(str1)
tmp1.flush()
tmp2.write(str2)
tmp2.flush()
out = subprocess.run(
["git", "--no-pager", "diff", "--color-words=.", tmp1.name, tmp2.name],
capture_output=True
)
print(out.stdout.decode())
def print_diff(str1: str, str2: str) -> None:
d = Differ()
results = d.compare(str1.splitlines(), str2.splitlines())
sys.stdout.writelines(results)
if __name__ == '__main__':
print_diff_call("something\nnw", "someting\nnew")