refiled directories

This commit is contained in:
2026-03-31 13:58:19 -05:00
parent b669e6349d
commit e145ba949b
6 changed files with 119 additions and 258 deletions

View File

@@ -7,7 +7,6 @@ from typing import Literal
def _run(cmd: list[str]) -> str:
"""Run a command and return stripped stdout (empty string on failure)."""
try:
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
return result.stdout.strip()
@@ -16,12 +15,10 @@ def _run(cmd: list[str]) -> str:
def is_active(unit: str, scope: Literal["system", "user"] = "system") -> str:
"""Return the ActiveState string (active / inactive / failed / …)."""
return _run(["systemctl", f"--{scope}", "is-active", unit]) or "unknown"
def is_enabled(unit: str, scope: Literal["system", "user"] = "system") -> str:
"""Return the UnitFileState string (enabled / disabled / masked / …)."""
return _run(["systemctl", f"--{scope}", "is-enabled", unit]) or "unknown"
@@ -31,18 +28,11 @@ def run_action(
scope: Literal["system", "user"] = "system",
method: str = "systemctl",
) -> bool:
"""Start / stop / restart a unit.
For *system* units the command is elevated via *method* (pkexec or sudo).
Returns True on apparent success.
"""
base_cmd = ["systemctl", f"--{scope}", action, unit]
if scope == "system" and method == "pkexec":
cmd = ["pkexec", "--user", "root"] + base_cmd
else:
cmd = base_cmd
try:
subprocess.Popen(cmd)
return True