#!/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 """ import collections import os import sys SRC = "/root/troupe-standup/repo_files.tsv" 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(" ") if not line.strip(): continue if line.startswith("rank path"): continue key, _, val = line.partition(" ") 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 " % (len(rows), total)) with open(OUT, "w") as fh: fh.write("rank extension file_count ") for i, (ext, n) in enumerate(cnt.most_common(), 1): fh.write("%d %s %d " % (i, ext, n)) print("rows=%d total=%d -> %s" % (len(rows), total, OUT)) if __name__ == "__main__": main()