# SPDX-License-Identifier: MIT """Replace the @@WITHDRAWN:label@@ placeholders of a file with text from a JSON map.""" import json, sys path, mapping = sys.argv[1], json.load(open(sys.argv[2])) text = open(path).read() for label, new in mapping.items(): marker = f"// @@WITHDRAWN:{label}@@" i = text.index(marker) start = text.rfind("\n", 0, i) + 1 end = i + len(marker) text = text[:start] + new.rstrip("\n") + text[end:] print("filled", label) assert "@@WITHDRAWN" not in text, "placeholders left" open(path, "w").write(text)