summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-03-15 22:20:21 +0100
committerDavid Robillard <d@drobilla.net>2019-03-17 00:31:46 +0100
commit387c1dfa6fbebc9d75bd80231f69baf94346dce1 (patch)
tree0988825659214b8bca4a77aaccf43cd5dd5d40d7
parent29d4d293d23759b39e152241ab3669583afbdeca (diff)
downloadautowaf-387c1dfa6fbebc9d75bd80231f69baf94346dce1.tar.gz
autowaf-387c1dfa6fbebc9d75bd80231f69baf94346dce1.tar.bz2
autowaf-387c1dfa6fbebc9d75bd80231f69baf94346dce1.zip
Add show_diff() and test_file_equals() utilities
-rw-r--r--extras/autowaf.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/extras/autowaf.py b/extras/autowaf.py
index 554c312..91edfee 100644
--- a/extras/autowaf.py
+++ b/extras/autowaf.py
@@ -775,6 +775,34 @@ def cd_to_orig_dir(ctx, child):
else:
os.chdir('..')
+def show_diff(from_lines, to_lines, from_filename, to_filename):
+ import difflib
+ import sys
+
+ for line in difflib.unified_diff(
+ from_lines, to_lines,
+ fromfile=os.path.abspath(from_filename),
+ tofile=os.path.abspath(to_filename)):
+ sys.stderr.write(line)
+
+def test_file_equals(patha, pathb):
+ import filecmp
+ import io
+
+ for path in (patha, pathb):
+ if not os.access(path, os.F_OK):
+ Logs.pprint('RED', 'error: missing file %s' % path)
+ return False
+
+ if filecmp.cmp(patha, pathb, shallow=False):
+ return True
+
+ with io.open(patha, 'rU', encoding='utf-8') as fa:
+ with io.open(pathb, 'rU', encoding='utf-8') as fb:
+ show_diff(fa.readlines(), fb.readlines(), patha, pathb)
+
+ return False
+
def bench_time():
if hasattr(time, 'perf_counter'): # Added in Python 3.3
return time.perf_counter()