Files

48 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
"""Ledger — extract the committed replies/ tree into a machine-readable catalog.
Source: `git ls-tree -r -l HEAD replies/`.
For every tracked reply file we record the relative path, the on-disk size of the
blob and the git blob SHA. One row per file, tab-separated, sorted by path.
Output: wizard-work/ledger/replies-catalog.tsv
"""
import os
import subprocess
import sys
from pathlib import Path
REPO = Path("/root/troupe-standup")
OUT = REPO / "wizard-work" / "ledger" / "replies-catalog.tsv"
def ls_tree(repo: Path):
"""Yield (rel_path, size, blob_sha) for every tracked blob under replies/."""
proc = subprocess.run(
["git", "ls-tree", "-r", "-l", "HEAD", "replies/"],
cwd=repo,
check=True,
capture_output=True,
text=True,
)
for line in proc.stdout.splitlines():
# git ls-tree -l prints: mode type object size<TAB>path (whitespace-separated)
parts = line.split()
if len(parts) == 5 and parts[0] == "100644" and parts[1] == "blob":
mode, otype, obj, size, path = parts
yield path, int(size), obj
def main():
rows = sorted(ls_tree(REPO))
with OUT.open("w", encoding="utf-8", newline="") as fh:
fh.write("file\tsize_bytes\tblob_sha\n")
for path, size, sha in rows:
fh.write("{}\t{}\t{}\n".format(path, size, sha))
print("wrote {} rows -> {}".format(len(rows), OUT))
if __name__ == "__main__":
main()