#!/usr/bin/env python3 """ variants-report.py - inventory of resource/Variants/*.mw4 (saved mechlab loadouts). python3 variants-report.py A variant package holds 4 records: [0] 'Resource\\Variants\\' 4 B (raw id) [1] '{Mech}' ~350 B [2] '{Subsystem}' ~4 KB <- names the chassis it needs [3] '<8-char token>' 16 B So the chassis a variant depends on is readable straight from the manifest, with no decompression: the record whose name ends in '{Subsystem}'. The report groups variants by chassis and flags any whose chassis is absent from the target build's core.mw4 (those will not load). """ import sys, os, collections def chassis_in_core(manifest): """Set of chassis names that core.mw4 defines (one *.subsystems per chassis).""" out = set() with open(manifest, encoding="latin-1") as fh: for line in fh: pkg, _rid, name, *_ = line.rstrip("\n").split("\t") if pkg.lower() != "core.mw4": continue n = name.lower().replace("\\", "/") if n.endswith(".subsystems"): out.add(n.rsplit("/", 1)[-1][:-len(".subsystems")]) return out def variant_chassis(manifest): """variantPkgRelPath -> chassis name it requires.""" out = {} with open(manifest, encoding="latin-1") as fh: for line in fh: pkg, _rid, name, *_ = line.rstrip("\n").split("\t") if not pkg.lower().startswith("variants/"): continue if name.endswith("{Subsystem}"): out[pkg] = name[:-len("{Subsystem}")].lower() return out def main(): if len(sys.argv) != 4: sys.exit(__doc__) vdir, v4h_manifest, ours_manifest = sys.argv[1:4] have_v4h = chassis_in_core(v4h_manifest) have_ours = chassis_in_core(ours_manifest) vc = variant_chassis(v4h_manifest) print(f"# variant packages: {len(vc)} (files on disk: " f"{len([f for f in os.listdir(vdir) if f.lower().endswith('.mw4')])})") print(f"# chassis defined in V4H core.mw4 : {len(have_v4h)}") print(f"# chassis defined in OUR core.mw4 : {len(have_ours)}") print(f"# chassis only V4H defines : {sorted(have_v4h - have_ours)}") print() by = collections.defaultdict(list) for pkg, ch in vc.items(): by[ch].append(pkg) loadable_now = broken = needs_new_mech = 0 print(f"{'chassis':22s} {'count':>5s} status") for ch in sorted(by, key=lambda c: (-len(by[c]), c)): n = len(by[ch]) if ch in have_ours: status = "loadable in OUR build today" loadable_now += n elif ch in have_v4h: status = "needs the new chassis ported" needs_new_mech += n else: status = "BROKEN - chassis missing from V4H too" broken += n print(f"{ch:22s} {n:5d} {status}") print() print(f"loadable in our build today : {loadable_now}") print(f"blocked on new chassis : {needs_new_mech}") print(f"broken / orphaned : {broken}") for ch in sorted(by): if ch not in have_v4h: print(f" orphan chassis '{ch}': " + ", ".join(sorted(by[ch]))) if __name__ == "__main__": main()