micropython/ports/zephyr/makeprj.py
Damien George 01dd7804b8 ports: Make new ports/ sub-directory and move all ports there.
This is to keep the top-level directory clean, to make it clear what is
core and what is a port, and to allow the repository to grow with new ports
in a sustainable way.
2017-09-06 13:40:51 +10:00

30 lines
656 B
Python

#!/usr/bin/env python3
import sys
import os
import hashlib
def hash_file(fname):
if not os.path.exists(fname):
return b""
hasher = hashlib.md5()
with open(fname, "rb") as f:
hasher.update(f.read())
return hasher.digest()
old_digest = hash_file(sys.argv[3])
with open(sys.argv[3] + ".tmp", "wb") as f:
f.write(open(sys.argv[1], "rb").read())
if os.path.exists(sys.argv[2]):
f.write(open(sys.argv[2], "rb").read())
new_digest = hash_file(sys.argv[3] + ".tmp")
if new_digest != old_digest:
print("Replacing")
os.rename(sys.argv[3] + ".tmp", sys.argv[3])
else:
os.remove(sys.argv[3] + ".tmp")