from pathlib import Path
import xml.etree.ElementTree as E
import wx
_app=wx.App(False)
import pcbnew as k
D=Path(__file__).resolve().parent/'power_board';p=D/'lamp_buck_lmr51450_a5_ctrl3v3.kicad_pcb';b=k.LoadBoard(str(p));r=E.parse(D/'netlist.xml').getroot();cs={c.get('ref'):c for c in r.findall('./components/comp')}
for f in b.GetFootprints():
 if f.GetReference() not in ('U4','C15','C16'):continue
 c=cs[f.GetReference()];f.SetValue(c.findtext('value'));f.SetFPIDAsString(c.findtext('footprint'))
 if f.GetReference()=='U4':
  nn='unconnected-(U4-NC-Pad4)';net=b.FindNet(nn)
  if net is None:net=k.NETINFO_ITEM(b,nn);b.Add(net)
  for pad in f.Pads():
   if pad.GetNumber()=='4':pad.SetNet(net)
k.SaveBoard(str(p),b)
