#!/usr/bin/env python3 """ mw4index.py - fast TSV manifest of every *.mw4 package under a directory. python3 mw4index.py > manifest.tsv Columns: pkgRelPath \t recordId \t entryName \t dataLen \t recLen \t md5(storedBytes) Directory-only, so a 780 MB resource tree indexes in about a second. CAUTION: md5 of the *stored* bytes is NOT a reliable equality test. Two builds that packed identical source can still produce different stored bytes (raw vs LZW selection, dictionary state). Use it only as a cheap "definitely identical" signal; confirm real differences with pkgcmp.py, which decodes. """ import sys, os sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from mw4db import read_index, walk_packages, md5 def main(): if len(sys.argv) != 2: sys.exit(__doc__) root = sys.argv[1] for path, rel in walk_packages(root): try: r = read_index(path) except Exception as e: # truncated / unreadable package print(f"!ERR\t{rel}\t{e}", file=sys.stderr) continue if r is None: print(f"!NOTVBD\t{rel}", file=sys.stderr) continue _content, recs = r for rid, name, dlen, rlen, raw in recs: print(f"{rel}\t{rid}\t{name}\t{dlen}\t{rlen}\t{md5(raw)}") if __name__ == "__main__": main()