Files
vibemake-pcb-studio/integration/install-editor-export.py
T
2026-11-04 17:12:56 +08:00

21 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Optional backend capability: add an immutable legacy epro artifact for Ziro.
Run on the PCB server: python3 integration/install-editor-export.py ~/auto_pcb
No credentials are read or copied. Existing frozen deliveries are unchanged.
"""
import ast,os,pathlib,shutil,sqlite3,sys,time
root=pathlib.Path(sys.argv[1]).expanduser().resolve();path=root/'deliver_pack/design_runtime/eda.py'
source=path.read_text();line=' (\'editor_native\',\'pcb\',\'eda.sys_FileManager.getProjectFile("design-editor",undefined,"epro")\',\'native/design-editor.epro\'),\n'
if line in source:print('Editor export already installed');raise SystemExit(0)
dbpath=root/'runtime/web-v3/api.sqlite3'
if dbpath.exists():
db=sqlite3.connect('file:'+str(dbpath)+'?mode=ro',uri=True)
if db.execute("select 1 from operations where state in ('queued','running')").fetchone():raise SystemExit('An operation is active; retry after it finishes.')
db.close()
anchor=' (\'schematic\',\'schematic\',\'eda.sch_ManufactureData.getPngFile("schematic",{width:1800})\',\'schematic/schematic.png\'),\n'
if source.count(anchor)!=1:raise SystemExit('Backend version differs: expected export entry not found. No change made.')
updated=source.replace(anchor,line+anchor);ast.parse(updated)
backup=root/'runtime/repair-backups'/time.strftime('%Y%m%d-%H%M%S-ziro-editor');backup.mkdir(parents=True);shutil.copy2(path,backup/'eda.py')
temp=path.with_name(path.name+'.ziro-tmp');temp.write_text(updated);os.replace(temp,path)
print('Installed. New tasks export native/design-editor.epro; backup:',backup)