#!/usr/bin/env python3 """ext-census: extension census of the Troupe standup repo. Reads the curated file census `repo_files.tsv` (3,344 data rows) in the troupe repo, applies a stated rule, and emits an ordered table of extension -> file_count. Rule ---- basename = final path component. . dotfile (leading dot, e.g. .gitignore) -> "(none)" . no dot in basename -> "(none)" . otherwise -> substring after LAST dot, lowercased Paths default to the curated census at the repo root and to the ledger artifact, and are overridable with EXT_CENSUS_SRC / EXT_CENSUS_OUT so a reader can regenerate into scratch instead of clobbering the committed table. (Q101: four string literals had a real line break where "\n" belonged, so this file did not compile; repaired 2026-10-27.) """ import collections import os import sys SRC = os.environ.get("EXT_CENSUS_SRC", "/root/troupe-standup/repo_files.tsv") OUT = os.environ.get( "EXT_CENSUS_OUT", "/root/.hermes/wizard-outputs/ledger/ext-census.tsv" ) def ext_of(basename): if basename.startswith(".") or "." not in basename: return "(none)" return basename.rsplit(".", 1)[1].lower() def parse_census(path): rows = [] with open(path) as fh: for line in fh: line = line.rstrip("\n") if not line.strip(): continue if line.startswith("rank\tpath"): continue key, _, val = line.partition("\t") rows.append((key.strip(), val.strip())) return rows def main(): rows = parse_census(SRC) cnt = collections.Counter(ext_of(os.path.basename(p)) for _, p in rows) total = sum(cnt.values()) if total != len(rows): sys.stderr.write("WARNING: parsed rows=%d counts=%d\n" % (len(rows), total)) with open(OUT, "w") as fh: fh.write("rank\textension\tfile_count\n") for i, (ext, n) in enumerate(cnt.most_common(), 1): fh.write("%d\t%s\t%d\n" % (i, ext, n)) print("rows=%d total=%d -> %s" % (len(rows), total, OUT)) if __name__ == "__main__": main()