#!/usr/bin/env python3 """ pkgcmp.py - authoritative content diff of two versions of the same *.mw4. python3 pkgcmp.py Decodes every record on both sides and compares the *decompressed* bytes, so the result is free of packer noise. This is the only trustworthy equality test; stored-byte comparison badly over-reports (peaks.mw4: 9 stored-byte diffs, 1 real one). Throughput is roughly 2 MB/s of package (props.mw4, 114 MB, takes ~50 s). """ import sys, os sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from mw4db import read_records, norm, md5 def load(path): _content, recs = read_records(path) return {norm(name): (dlen, md5(blob), blob) for _rid, name, dlen, _rlen, blob in recs} def main(): if len(sys.argv) != 3: sys.exit(__doc__) a, b = load(sys.argv[1]), load(sys.argv[2]) aonly = sorted(set(a) - set(b)) bonly = sorted(set(b) - set(a)) diff = sorted(k for k in set(a) & set(b) if a[k][1] != b[k][1]) print(f"# entries: A={len(a)} B={len(b)} " f"A_only={len(aonly)} B_only={len(bonly)} decoded-differ={len(diff)}") for k in aonly: print(f"+A {k} {a[k][0]}B") for k in bonly: print(f"-B {k} {b[k][0]}B") for k in diff: print(f"~ {k} A={a[k][0]}B B={b[k][0]}B") if __name__ == "__main__": main()