mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-09 09:08:15 -06:00
Tmp with difflib
This commit is contained in:
parent
292bebdc0e
commit
6196eb2eb6
@ -1,4 +1,5 @@
|
|||||||
import decimal
|
import decimal
|
||||||
|
import difflib
|
||||||
from itertools import count, groupby
|
from itertools import count, groupby
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -161,6 +162,24 @@ def make_diff(old: str, new: str):
|
|||||||
new_lines = new.splitlines(False)
|
new_lines = new.splitlines(False)
|
||||||
old_list: list[tuple[str, bool]] = []
|
old_list: list[tuple[str, bool]] = []
|
||||||
new_list: list[tuple[str, bool]] = []
|
new_list: list[tuple[str, bool]] = []
|
||||||
|
if True:
|
||||||
|
old_lines = old.splitlines(True)
|
||||||
|
new_lines = new.splitlines(True)
|
||||||
|
differ = difflib.Differ()
|
||||||
|
x = list(differ.compare(old_lines, new_lines))
|
||||||
|
for val in x:
|
||||||
|
op = val[0]
|
||||||
|
raw = val[2:].replace("\n", "").replace("\r", "")
|
||||||
|
if op == ' ':
|
||||||
|
old_list.append((raw, False))
|
||||||
|
new_list.append((raw, False))
|
||||||
|
elif op == '+':
|
||||||
|
old_list.append(('', True))
|
||||||
|
new_list.append((raw, True))
|
||||||
|
elif op == '-':
|
||||||
|
old_list.append((raw, True))
|
||||||
|
new_list.append(('', True))
|
||||||
|
return old_list, new_list
|
||||||
old_idx = 0
|
old_idx = 0
|
||||||
new_idx = 0
|
new_idx = 0
|
||||||
while True:
|
while True:
|
||||||
|
Loading…
Reference in New Issue
Block a user