From bf8268f40234518976136db99a3cf2e32f89a25d Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Fri, 9 Sep 2022 14:29:35 -0700 Subject: [PATCH] Code to checksum all py files in a dir. Useful for checking repo state --- protdiff/utils.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/protdiff/utils.py b/protdiff/utils.py index 17d227b..a5e6670 100644 --- a/protdiff/utils.py +++ b/protdiff/utils.py @@ -1,11 +1,13 @@ """ Misc shared utility functions """ +import os +import glob +import hashlib import logging from typing import * import numpy as np -import torch def extract(a, t, x_shape): @@ -110,6 +112,18 @@ def update_dict_nonnull(d: Dict[str, Any], vals: Dict[str, Any]) -> Dict[str, An return d +def md5_all_py_files(dirname: str) -> str: + """Create a single md5 sum for all given files""" + # https://stackoverflow.com/questions/36099331/how-to-grab-all-files-in-a-folder-and-get-their-md5-hash-in-python + fnames = glob.glob(os.path.join(dirname, "*.py")) + hash_md5 = hashlib.md5() + for fname in sorted(fnames): + with open(fname, "rb") as f: + for chunk in iter(lambda: f.read(2**20), b""): + hash_md5.update(chunk) + return hash_md5.hexdigest() + + if __name__ == "__main__": import doctest