Skip to content

Commit 58ad8da

Browse files
committed
[fdiff.diff] add initial implementation of unified diff
1 parent 3538a95 commit 58ad8da

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lib/fdiff/diff.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
import tempfile
3+
4+
from fontTools.ttLib import TTFont
5+
6+
from fdiff.utils import get_file_modtime
7+
from fdiff.thirdparty.fdifflib import unified_diff
8+
9+
10+
def u_diff(filepath_a, filepath_b, context_lines):
11+
tt_left = TTFont(filepath_a)
12+
tt_right = TTFont(filepath_b)
13+
14+
fromdate = get_file_modtime(filepath_a)
15+
todate = get_file_modtime(filepath_b)
16+
17+
with tempfile.TemporaryDirectory() as tmpdirname:
18+
tt_left.saveXML(os.path.join(tmpdirname, "left.ttx"))
19+
tt_right.saveXML(os.path.join(tmpdirname, "right.ttx"))
20+
21+
with open(os.path.join(tmpdirname, "left.ttx")) as ff:
22+
fromlines = ff.readlines()
23+
with open(os.path.join(tmpdirname, "right.ttx")) as tf:
24+
tolines = tf.readlines()
25+
26+
return unified_diff(
27+
fromlines,
28+
tolines,
29+
filepath_a,
30+
filepath_b,
31+
fromdate,
32+
todate,
33+
n=context_lines,
34+
)

0 commit comments

Comments
 (0)