#!/usr/bin/env python3 from __future__ import annotations import argparse from pathlib import Path def main(): ap = argparse.ArgumentParser() ap.add_argument('--file', required=True) ap.add_argument('--items', required=True) args = ap.parse_args() p = Path(args.file) items = Path(args.items).read_text(encoding='utf-8') s = p.read_text(encoding='utf-8') marker = 'const CourseItem items[] = {' i = s.find(marker) if i < 0: raise SystemExit(f'cannot find marker: {marker}') j = s.find('};', i) if j < 0: raise SystemExit('cannot find end marker "};" after items start') before = s[:i] after = s[j+2:] out = before + items + after if out == s: print('no change') return backup = p.with_suffix(p.suffix + '.bak_cppbasic20') backup.write_text(s, encoding='utf-8') p.write_text(out, encoding='utf-8') print('patched', str(p)) print('backup', str(backup)) if __name__ == '__main__': main()