import os, pathlib, subprocess, sys
root=pathlib.Path('/home/lighthouse/esp32-dev/.cache/speech-playback-diagnostics-20261006/.cache/speech-diagnostics')
drop=pathlib.Path('/run/user/1000/systemd/user/device-gateway.service.d/zzzzz-speech-trace.conf')
if sys.argv[1]=='enable':
    assert not drop.exists(), 'Diagnostic override already exists'
    drop.parent.mkdir(parents=True,exist_ok=True)
    drop.write_text('[Service]\nExecStart=\nExecStart=/home/lighthouse/esp32-dev/.cache/double-click-shortcuts-0.6.3/server/.venv/bin/python '+str(root/'wss_trace_gateway.py')+'\n')
elif sys.argv[1]=='restore':
    drop.unlink(missing_ok=True)
else:
    raise SystemExit('enable or restore')
subprocess.run(['systemctl','--user','daemon-reload'],check=True)
subprocess.run(['systemctl','--user','restart','device-gateway.service'],check=True)
subprocess.run(['systemctl','--user','is-active','device-gateway.service'],check=True)
