File size: 1,570 Bytes
2b3f8d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
from pathlib import Path
import hashlib
import argparse


parser = argparse.ArgumentParser()
parser.add_argument("--root", default=".")
parser.add_argument("--out", default="SHA256SUMS.txt")
parser.add_argument("--exclude-dist", action="store_true")
parser.add_argument("--include-safe-subset", action="store_true")
args = parser.parse_args()

root = Path(args.root)
files = []


def is_lfs_pointer(path):
    try:
        return path.read_bytes()[:120].startswith(b"version https://git-lfs.github.com/spec/v1")
    except OSError:
        return False


for p in root.rglob("*"):
    if not p.is_file():
        continue
    rel = p.relative_to(root).as_posix()
    if rel == args.out:
        continue
    if args.exclude_dist and rel.startswith("dist/"):
        continue
    if not args.include_safe_subset and rel.startswith("safe_public_subset/"):
        continue
    if ".git/" in rel or rel.startswith(".git/"):
        continue
    if "__pycache__/" in rel or rel.endswith(".pyc"):
        continue
    files.append(p)

lines = []
pointer_files = []
for p in sorted(files):
    if is_lfs_pointer(p):
        pointer_files.append(p.relative_to(root).as_posix())
    h = hashlib.sha256(p.read_bytes()).hexdigest()
    lines.append(f"{h}  {p.relative_to(root).as_posix()}")

Path(args.out).write_text("\n".join(lines) + "\n", encoding="utf-8")
print(f"Wrote {args.out} with {len(lines)} files")
if pointer_files:
    print("Warning: hashed Git LFS pointer files, not full payloads:")
    for rel in pointer_files:
        print(f"- {rel}")