diff options
Diffstat (limited to 'contrib/scripts/pydiffer.py.in')
-rw-r--r-- | contrib/scripts/pydiffer.py.in | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/contrib/scripts/pydiffer.py.in b/contrib/scripts/pydiffer.py.in new file mode 100644 index 000000000..10145371c --- /dev/null +++ b/contrib/scripts/pydiffer.py.in | |||
@@ -0,0 +1,44 @@ | |||
1 | #!@PYTHON@ | ||
2 | import os | ||
3 | import sys | ||
4 | import difflib | ||
5 | import filecmp | ||
6 | |||
7 | |||
8 | def getdiff(old, new): | ||
9 | diff = [] | ||
10 | with open(old) as a: | ||
11 | with open(new) as b: | ||
12 | for l in difflib.unified_diff(a.read().splitlines(), b.read().splitlines()): | ||
13 | diff.append(l) | ||
14 | return diff | ||
15 | |||
16 | |||
17 | def dc_getdiff(dc, old, new): | ||
18 | diff = [] | ||
19 | for f in dc.left_only: | ||
20 | diff.append("Only in {}: {}".format(old, f)) | ||
21 | for f in dc.right_only: | ||
22 | diff.append("Only in {}: {}".format(new, f)) | ||
23 | for f in dc.diff_files: | ||
24 | r = getdiff(os.path.join(old, f), os.path.join(new, f)) | ||
25 | diff.extend(r) | ||
26 | for dn, dc in dc.subdirs.items(): | ||
27 | r = dc_getdiff(dc, os.path.join(old, dn), os.path.join(new, dn)) | ||
28 | diff.extend(r) | ||
29 | return diff | ||
30 | |||
31 | |||
32 | def dcdiff(old, new): | ||
33 | dc = filecmp.dircmp(old, new) | ||
34 | diff = dc_getdiff(dc, old, new) | ||
35 | return diff | ||
36 | |||
37 | |||
38 | def main(): | ||
39 | for l in dcdiff(sys.argv[1], sys.argv[2]): | ||
40 | print(l) | ||
41 | |||
42 | |||
43 | if __name__ == '__main__': | ||
44 | main() | ||