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

25 lines
765 B
Python
Raw Normal View History

2022-07-03 00:14:51 +02:00
import subprocess
import sys
from difflib import Differ
from tempfile import NamedTemporaryFile
def print_diff_call(str1: str, str2: str, title: str) -> None:
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()
2022-07-03 00:17:16 +02:00
subprocess.run(["git", "--no-pager", "diff", "--color-words=.", tmp1.name, tmp2.name])
2022-07-03 00:14:51 +02:00
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")