orca/scripts/checksum.py

31 lines
739 B
Python
Raw Normal View History

import hashlib
import json
from log import *
2023-07-08 22:21:01 +00:00
def checkfile(filepath):
newsum = filesum(filepath)
sums = {}
with open("scripts/checksums.json", "r") as sumsfile:
sums = json.loads(sumsfile.read())
2023-07-08 22:21:01 +00:00
if filepath not in sums:
msg = log_warning(f"no checksum saved for file {filepath}")
msg.more(f"file had checksum: {newsum}")
return False
2023-07-08 22:21:01 +00:00
sum = sums[filepath]
if sum != newsum:
msg = log_warning(f"checksums did not match for {filepath}:")
msg.more(f"expected: {sum}")
msg.more(f" got: {newsum}")
return False
return True
def filesum(filepath):
with open(filepath, "rb") as file:
return hashlib.sha256(file.read()).hexdigest()