56 lines
1.7 KiB
Python
Executable File
56 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# verify_census: re-derive the extension census from repo_files.tsv and diff it
|
|
# against the committed ext-census.tsv. Exit 0 iff identical.
|
|
import collections
|
|
import os
|
|
import sys
|
|
|
|
REPO = "/root/troupe-standup"
|
|
CATALOG = "/root/.hermes/wizard-outputs/ledger/ext-census.tsv"
|
|
|
|
def ext_of(b):
|
|
if b.startswith(".") or "." not in b:
|
|
return "(none)"
|
|
return b.rsplit(".", 1)[1].lower()
|
|
|
|
def rederived():
|
|
cnt = collections.Counter()
|
|
with open(os.path.join(REPO, "repo_files.tsv")) as fh:
|
|
for line in fh:
|
|
line = line.rstrip("\n")
|
|
if not line.strip() or line.startswith("rank\tpath"):
|
|
continue
|
|
_, _, p = line.partition("\t")
|
|
cnt[ext_of(os.path.basename(p.strip()))] += 1
|
|
return cnt
|
|
|
|
def read_catalog():
|
|
out = {}
|
|
with open(CATALOG) as fh:
|
|
next(fh) # header
|
|
for line in fh:
|
|
parts = line.rstrip("\n").split("\t")
|
|
if len(parts) == 3:
|
|
out[parts[1]] = int(parts[2])
|
|
return out
|
|
|
|
def main():
|
|
want = rederived()
|
|
got = read_catalog()
|
|
keys = sorted(set(want) | set(got), key=lambda k: (-want.get(k, 0), k))
|
|
bad = 0
|
|
for k in keys:
|
|
w = want.get(k, 0)
|
|
g = got.get(k, 0)
|
|
if w != g:
|
|
bad += 1
|
|
print("MISMATCH " + k + ": rederived=" + str(w) + " catalog=" + str(g))
|
|
if want != got:
|
|
print("FAIL: catalog differs from re-derivation (" + str(bad) + " mismatched rows)")
|
|
return 1
|
|
print("PASS: " + str(len(keys)) + " extension rows; " + str(sum(want.values())) + " files match the re-derived census")
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|