Add missing frontend and backend files

This commit is contained in:
2026-05-06 23:46:08 +02:00
parent b789034bbe
commit 016e3255f5
20 changed files with 5226 additions and 0 deletions
@@ -0,0 +1,60 @@
"""Local command execution helpers.
These mirror the remote SSH helpers but execute commands on the API host
itself. They are used for the built-in local monitoring machine.
"""
from __future__ import annotations
import logging
import posixpath
import subprocess
from dataclasses import dataclass
logger = logging.getLogger(__name__)
@dataclass
class CommandResult:
"""Plain result object returned by local command execution."""
command: str
exit_status: int
stdout: str
stderr: str
class LocalCommandClient:
"""Execute the same POSIX shell snippets used by the SSH client locally."""
def __init__(self, timeout: int = 20):
self.timeout = timeout
def run(self, command: str, timeout: int | None = None) -> CommandResult:
shell_command = ["/bin/sh", "-c", command]
logger.debug("Local run timeout=%s command=%s", timeout or self.timeout, command)
proc = subprocess.run(
shell_command,
capture_output=True,
text=True,
timeout=timeout or self.timeout,
)
result = CommandResult(
command=command,
exit_status=proc.returncode,
stdout=proc.stdout,
stderr=proc.stderr,
)
if result.exit_status == 0:
logger.debug("Local command ok exit_status=%s", result.exit_status)
else:
logger.warning(
"Local command failed exit_status=%s stderr=%s",
result.exit_status,
result.stderr.strip() or result.stdout.strip(),
)
return result
@staticmethod
def join(parent: str, child: str) -> str:
return posixpath.normpath(posixpath.join(parent, child))