Documentation, comments and small changes

This commit is contained in:
2026-09-27 16:18:35 +03:00
parent 0e43b943c4
commit e1e164bd65
8 changed files with 653 additions and 211 deletions
+19
View File
@@ -24,6 +24,8 @@ from topology_plan import (
)
# =========================== Rendering helpers ===========================
def _python_string(value: str) -> str:
"""Return a safe Python string literal.
@@ -187,6 +189,12 @@ def _render_gateway_configuration(interface: PlannedInterface) -> List[str]:
def _render_service_start(service: PlannedService, index: int) -> List[str]:
"""Render startup code for one planned service.
Construct dnsmasq arguments from the resolved binding and DHCP settings,
using the service index for lease, PID, and log filenames.
Emit commands that remove previous lease and PID files, launch the daemon
in the background, and record its shell PID for later cleanup.
The emitted startup sequence does not check daemon readiness.
Args:
service: Fully resolved service operation.
index: Stable service index used for temporary runtime files.
@@ -238,9 +246,18 @@ def _render_service_start(service: PlannedService, index: int) -> List[str]:
]
# ============================ Public interface ============================
def render_python(plan: ExecutionPlan) -> str:
"""Render an execution plan as a complete executable Python program.
Assemble source lines for runtime helpers and the network lifecycle.
Emit construction first so interfaces exist before configuration; emit
addresses before default routes and services that depend on them.
Finish with the interactive CLI and a finally block that attempts tracked
service cleanup followed by network shutdown.
Rendering itself only produces text and does not execute these operations.
Args:
plan: Fully resolved execution plan returned by topology_plan.plan().
@@ -377,6 +394,8 @@ def render_python(plan: ExecutionPlan) -> str:
return "\n".join(lines)
# =============================== Self-test ===============================
def _self_test() -> None:
"""Run a smoke test against the public render_python() interface."""