diff options
author | LRN <lrn1986@gmail.com> | 2012-07-22 13:47:14 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2012-07-22 13:47:14 +0000 |
commit | 3e578a363db4b1b5840c06a9ac2ac54a68fb6657 (patch) | |
tree | 8ec86a2a71759f4cf0de97043aa5343cc68c3fc9 /contrib/pydiffer.py.in | |
parent | a669108f0f2d602bfea9c7a8132fb761388493ad (diff) | |
download | gnunet-3e578a363db4b1b5840c06a9ac2ac54a68fb6657.tar.gz gnunet-3e578a363db4b1b5840c06a9ac2ac54a68fb6657.zip |
Use Python batteries in fs_rec test
Diffstat (limited to 'contrib/pydiffer.py.in')
-rw-r--r-- | contrib/pydiffer.py.in | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/contrib/pydiffer.py.in b/contrib/pydiffer.py.in new file mode 100644 index 000000000..23d546b25 --- /dev/null +++ b/contrib/pydiffer.py.in | |||
@@ -0,0 +1,39 @@ | |||
1 | #!@PYTHON@ | ||
2 | import os | ||
3 | import sys | ||
4 | import difflib | ||
5 | import filecmp | ||
6 | |||
7 | def getdiff (old, new): | ||
8 | diff = [] | ||
9 | with open (old) as a: | ||
10 | with open (new) as b: | ||
11 | for l in difflib.unified_diff (a.read ().splitlines (), b.read ().splitlines ()): | ||
12 | diff.append (l) | ||
13 | return diff | ||
14 | |||
15 | def dc_getdiff (dc, old, new): | ||
16 | diff = [] | ||
17 | for f in dc.left_only: | ||
18 | diff.append ("Only in {}: {}".format (old, f)) | ||
19 | for f in dc.right_only: | ||
20 | diff.append ("Only in {}: {}".format (new, f)) | ||
21 | for f in dc.diff_files: | ||
22 | r = getdiff (os.path.join (old, f), os.path.join (new, f)) | ||
23 | diff.extend (r) | ||
24 | for dn, dc in dc.subdirs.items (): | ||
25 | r = dc_getdiff (dc, os.path.join (old, dn), os.path.join (new, dn)) | ||
26 | diff.extend (r) | ||
27 | return diff | ||
28 | |||
29 | def dcdiff (old, new): | ||
30 | dc = filecmp.dircmp (old, new) | ||
31 | diff = dc_getdiff (dc, old, new) | ||
32 | return diff | ||
33 | |||
34 | def main (): | ||
35 | for l in dcdiff (sys.argv[1], sys.argv[2]): | ||
36 | print (l) | ||
37 | |||
38 | if __name__ == '__main__': | ||
39 | main () | ||