#!/usr/bin/env python3 """diff-snaps.py [FROM TO]... — what changed between two snaps of scratch guest 9202 (evidence/drill/). Read-only. With no argument it walks the whole drill in order and prints, for each snap, the baseline lines that moved against `1-repointed` and the itemised lines (containers, images, volumes, folders) that appeared or went against the snap before. Lines that always move (logs, metrics, the drive's used bytes, the controller's data) are marked NOISE, not hidden.""" import os, sys HERE = os.path.dirname(os.path.abspath(__file__)); D = os.path.join(HERE, "..", "evidence", "drill") ORDER = ["0-before", "1-repointed"] + [f"cheap-{i:02d}" for i in range(1, 11)] + [ "keep-1-installed", "keep-2-removed-kept", "keep-3-installed-again", "keep-4-removed-all", "drive-1-installed", "drive-2-remove-all-tried", "drive-4-installed-no-question", "drive-5-removed-kept-all", "drive-6-installed-fresh-2", "drive-7-removed-data-kept-2", "upd1-1-installed-from", "upd1-2-updated", "upd1-3-restored", "upd1-4-removed-all"] NOISE = ("container-logs", "controller-data-volume", "used", "var-log", "journal", "rootfs", "data-volume", "tmp") def base(l): out = {} for line in open(os.path.join(D, f"base-{l}.tsv"), encoding="utf-8"): p = line.rstrip("\n").split("\t") if len(p) >= 3: out[p[0]] = (p[1], p[2]) return out def detail(l): return set(x.rstrip("\n") for x in open(os.path.join(D, f"detail-{l}.tsv"), encoding="utf-8") if x.strip()) def show(a, b, ref): ba, bb = base(ref), base(b) print(f"\n=== {b} (baseline against {ref}; items against {a})") for k in bb: if k in ba and ba[k] != bb[k]: tag = "NOISE " if any(n in k for n in NOISE) else "MOVED " try: d = f"{int(bb[k][0]) - int(ba[k][0]):+d}" except ValueError: d = "?" print(f" {tag}{k} {ba[k][0]} -> {bb[k][0]} ({d}) {ba[k][1]} -> {bb[k][1]}") da, db = detail(a), detail(b) for x in sorted(db - da): print(" + " + x[:230]) for x in sorted(da - db): print(" - " + x[:230]) args = sys.argv[1:] if args: for i in range(0, len(args), 2): show(args[i], args[i + 1], args[i]) else: have = [l for l in ORDER if os.path.exists(os.path.join(D, f"base-{l}.tsv"))] for prev, cur in zip(have, have[1:]): show(prev, cur, "1-repointed")