#!/usr/bin/env python3
"""Make the one-byte controlled edit, without KiCad or a BoardPort comparison.
Put the archived destination.kicad-10.0.6.kicad_pcb and LICENSE.txt next to this script.
Run in a separate folder: python3 reproduce-placement.py
The output is an intentionally modified derivative, not an official KiCad export.
"""
from hashlib import sha256
from pathlib import Path

folder = Path(__file__).resolve().parent
original = (folder / 'destination.kicad-10.0.6.kicad_pcb').read_bytes()
if sha256(original).hexdigest() != 'a0671ba0c98c96bbfd8278fedc850baca9c88e21c98766acb122349f3ee457c2':
    raise SystemExit('Input differs from the archived import; no output written.')
if not (folder / 'LICENSE.txt').is_file():
    raise SystemExit('Retain the original BSD-3-Clause LICENSE.txt; no output written.')
before = b'(uuid "2be6bf36-1879-4222-b6ec-8e6e9ea9ece3")\n\t\t(at 1.143 -1.016)'
after = before.replace(b'(at 1.143 -1.016)', b'(at 2.143 -1.016)')
if original.count(before) != 1:
    raise SystemExit('Expected exactly one PAD2 position; no output written.')
modified = original.replace(before, after)
with (folder / 'moved-pad2-1mm.kicad_pcb').open('xb') as output:
    output.write(modified)
print('Created deliberately edited copy. No KiCad import, DRC or BoardPort comparison was run.')
print('SHA-256:', sha256(modified).hexdigest())
