# SPDX-License-Identifier: MIT """Move line ranges of a file, unread, into scratch/withdrawn/, leaving a placeholder line per range. Prints only labels and line counts.""" import json, os, sys path, spec = sys.argv[1], json.loads(sys.argv[2]) # [[label, first, last], ...] lines = open(path).read().split("\n") out_dir = os.path.join(os.path.dirname(__file__), "withdrawn") os.makedirs(out_dir, exist_ok=True) dest = os.path.join(out_dir, os.path.basename(path) + ".withdrawn") taken = [] for label, a, b in sorted(spec, key=lambda s: -s[1]): chunk = lines[a - 1:b] taken.append((label, a, chunk)) indent = len(lines[a - 1]) - len(lines[a - 1].lstrip()) lines[a - 1:b] = [" " * indent + f"// @@WITHDRAWN:{label}@@"] print(f"{label}: lines {a}-{b} ({len(chunk)} lines) withdrawn") with open(dest, "a") as f: for label, a, chunk in sorted(taken, key=lambda t: t[1]): f.write(f"==== {label} (from line {a})\n" + "\n".join(chunk) + "\n") open(path, "w").write("\n".join(lines))