File size: 1,633 Bytes
d23115f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import json
import os.path as op
import traceback
from glob import glob
from hashlib import sha256
from tqdm import tqdm
def main():
release_folder = "./downloads"
print("Globing files...")
fnames = glob(op.join(release_folder, "**/*"), recursive=True)
print("Number of files to checksum: ", len(fnames))
pbar = tqdm(fnames)
with open("./bash/assets/checksum.json", "r") as f:
gt_checksum = json.load(f)
hash_dict = {}
for fname in pbar:
if op.isdir(fname):
continue
if ".zip" not in fname:
continue
if "models_smplx_v1_1.zip" in fname:
continue
if "mano_v1_2.zip" in fname:
continue
try:
with open(fname, "rb") as f:
pbar.set_description(f"Reading {fname}")
data = f.read()
hashcode = sha256(data).hexdigest()
key = fname.replace(release_folder, "")
hash_dict[key] = hashcode
if hashcode != gt_checksum[key]:
print(f"Error: {fname} has different checksum!")
else:
pbar.set_description(f"Hashcode of {fname} is correct!")
# print(f'Hashcode of {fname} is correct!')
except:
print(f"Error processing {fname}")
traceback.print_exc()
continue
out_p = op.join(release_folder, "checksum.json")
with open(out_p, "w") as f:
json.dump(hash_dict, f, indent=4, sort_keys=True)
print(f"Checksum file saved to {out_p}!")
if __name__ == "__main__":
main()
|