2
0

pydiffer.py.in 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!@PYTHONEXE@
  2. import os
  3. import sys
  4. import difflib
  5. import filecmp
  6. def getdiff(old, new):
  7. diff = []
  8. with open(old) as a:
  9. with open(new) as b:
  10. for l in difflib.unified_diff(
  11. a.read().splitlines(),
  12. b.read().splitlines()
  13. ):
  14. diff.append(l)
  15. return diff
  16. def dc_getdiff(dc, old, new):
  17. diff = []
  18. for f in dc.left_only:
  19. diff.append("Only in {}: {}".format(old, f))
  20. for f in dc.right_only:
  21. diff.append("Only in {}: {}".format(new, f))
  22. for f in dc.diff_files:
  23. r = getdiff(os.path.join(old, f), os.path.join(new, f))
  24. diff.extend(r)
  25. for dn, dc in list(dc.subdirs.items()):
  26. r = dc_getdiff(dc, os.path.join(old, dn), os.path.join(new, dn))
  27. diff.extend(r)
  28. return diff
  29. def dcdiff(old, new):
  30. dc = filecmp.dircmp(old, new)
  31. diff = dc_getdiff(dc, old, new)
  32. return diff
  33. def main():
  34. for l in dcdiff(sys.argv[1], sys.argv[2]):
  35. print(l)
  36. if __name__ == '__main__':
  37. main()