makeprj.py 656 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env python3
  2. import sys
  3. import os
  4. import hashlib
  5. def hash_file(fname):
  6. if not os.path.exists(fname):
  7. return b""
  8. hasher = hashlib.md5()
  9. with open(fname, "rb") as f:
  10. hasher.update(f.read())
  11. return hasher.digest()
  12. old_digest = hash_file(sys.argv[3])
  13. with open(sys.argv[3] + ".tmp", "wb") as f:
  14. f.write(open(sys.argv[1], "rb").read())
  15. if os.path.exists(sys.argv[2]):
  16. f.write(open(sys.argv[2], "rb").read())
  17. new_digest = hash_file(sys.argv[3] + ".tmp")
  18. if new_digest != old_digest:
  19. print("Replacing")
  20. os.rename(sys.argv[3] + ".tmp", sys.argv[3])
  21. else:
  22. os.remove(sys.argv[3] + ".tmp")