compare.py 964 B

123456789101112131415161718192021222324252627282930313233
  1. '''
  2. Created on 22 nov. 2016
  3. @author: olivier.massot
  4. '''
  5. from ffile import flist
  6. import sys
  7. _, source_dir, reference_dir = sys.argv
  8. print("** Compare {} to {} **".format(source_dir, reference_dir))
  9. list_source_dir = flist(source_dir, recursive=True, listdirs=False, listfiles=True, complete_paths=True)
  10. list_reference_dir = flist(reference_dir, recursive=True, listdirs=False, listfiles=True, complete_paths=True)
  11. if len(list_source_dir) != len(list_reference_dir):
  12. print(">> number of dirs / files does not match")
  13. sys.exit(1)
  14. exit_code = 0
  15. for source_path in list_source_dir:
  16. with open(source_path, "rb") as source_file:
  17. ref_path = source_path.replace(source_dir, reference_dir)
  18. with open(ref_path, "rb") as ref_file:
  19. if source_file.read() != ref_file.read():
  20. print(">> {} do not match to ref".format(source_path))
  21. exit_code = 2
  22. sys.exit(exit_code)