73 lines
1.9 KiB
Python
73 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Independent ground-truth cross-check for the ledger extension census.
|
|
|
|
Walks `wizard-work/ledger/` two ways:
|
|
(A) os.walk
|
|
(B) `find -type f` via subprocess
|
|
and prints per-extension counts for each, plus the files that differ.
|
|
Exit 0 = both methods agree exactly.
|
|
"""
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from collections import Counter
|
|
|
|
ROOT = "wizard-work/ledger"
|
|
|
|
|
|
def ext_of(name):
|
|
if "." in name:
|
|
return "." + name.rsplit(".", 1)[1].lower()
|
|
return "(none)"
|
|
|
|
|
|
def via_oswalk():
|
|
c = Counter()
|
|
files = []
|
|
for dp, dn, fns in os.walk(ROOT):
|
|
for f in fns:
|
|
files.append(os.path.join(dp, f))
|
|
c[ext_of(f)] += 1
|
|
return c, files
|
|
|
|
|
|
def via_find():
|
|
out = subprocess.run(
|
|
["find", ROOT, "-type", "f"],
|
|
capture_output=True, text=True, check=True,
|
|
)
|
|
c = Counter()
|
|
files = []
|
|
for line in out.stdout.splitlines():
|
|
if not line:
|
|
continue
|
|
files.append(line)
|
|
c[ext_of(os.path.basename(line))] += 1
|
|
return c, files
|
|
|
|
|
|
def main():
|
|
a_c, a_files = via_oswalk()
|
|
b_c, b_files = via_find()
|
|
print("os.walk total=%d find total=%d" % (len(a_files), len(b_files)))
|
|
all_exts = sorted(set(a_c) | set(b_c))
|
|
for ext in sorted(all_exts, key=lambda e: (-a_c[e], e)):
|
|
print("%-10s oswalk=%d find=%d" % (ext, a_c.get(ext, 0), b_c.get(ext, 0)))
|
|
only_a = set(a_files) - set(b_files)
|
|
only_b = set(b_files) - set(a_files)
|
|
if only_a:
|
|
print("ONLY os.walk (%d):" % len(only_a))
|
|
for p in sorted(only_a):
|
|
print(" " + p)
|
|
if only_b:
|
|
print("ONLY find (%d):" % len(only_b))
|
|
for p in sorted(only_b):
|
|
print(" " + p)
|
|
if not only_a and not only_b:
|
|
print("AGREE: no file differences")
|
|
return 0 if (not only_a and not only_b) else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|