blob: 883abe05791c64a8939d94813714bf5f302b6aa3 [file] [edit]
import argparse
import hashlib
from typing import List
class Args(argparse.Namespace):
srcs: List[str]
out_file: str
def main():
parser = argparse.ArgumentParser(fromfile_prefix_chars="@")
parser.add_argument("--out-file", required=True, help="Path to the output file")
parser.add_argument("srcs", nargs="*", help="Paths of the source files to hash")
args = parser.parse_args(namespace=Args())
hasher = hashlib.sha256()
for filepath in sorted(args.srcs):
hasher.update(filepath.encode("utf-8"))
with open(filepath, "rb") as f:
while chunk := f.read(8192):
hasher.update(chunk)
hash_bytes = hasher.digest()[:8]
hash_int = int.from_bytes(hash_bytes, byteorder="big")
with open(args.out_file, "w") as f:
f.write(f"{hash_int:016x}\n")
if __name__ == "__main__":
main()