Files
lmxopcua/docs/ui-consistency/ot13-root-fields/check-protocol-boundaries.py
T
2026-11-13 20:23:31 -05:00

17 lines
1.3 KiB
Python

"""Guard protocol C# and event/bind expressions while associating native fields."""
from pathlib import Path
import subprocess,re,json
ROOT=Path(__file__).resolve().parents[3]
BASE=ROOT/'src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Shared'
files=[p for p in (BASE/'Drivers/Forms').glob('*DriverForm.razor') if p.stem!='CalculationDriverForm']+list((BASE/'Drivers/DeviceForms').glob('*DeviceForm.razor'))+list((BASE/'Uns/TagEditors').glob('*.razor'))
expr=re.compile(r'@(?:bind(?:-[\w]+)?(?::[\w]+)?|on[\w]+(?::[\w]+)?)\s*=\s*"[^"]*"')
rows=[]
for p in files:
old=subprocess.check_output(['git','show','a47ffb91:'+str(p.relative_to(ROOT))],cwd=ROOT,text=True);new=p.read_text();ob=old.split('@code {',1)[1];nb=new.split('@code {',1)[1]
assert nb.endswith(ob),p.name+' protocol C# changed'
prefix=nb[:-len(ob)]
assert all(line.strip().startswith(('private readonly string _fieldScope','private string FieldId','[CascadingParameter]')) for line in prefix.splitlines() if line.strip()),p.name+' unexpected new C#'
assert expr.findall(old.split('@code {')[0])==expr.findall(new.split('@code {')[0]),p.name+' binding/event expression changed'
rows.append({'component':p.stem,'protocolCSharpUnchanged':True,'eventAndBindExpressionsUnchanged':True,'migrated':bool(prefix)})
print(json.dumps(rows,indent=2))