mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
Setup writes the bundled Control's absolute paths (cwd, --expert-profile) into the run config; the AppImage mounts its Control at a new /tmp/.mount_<random> at every start. The host repaired them only at a status read, so the engine update's test start ran first with a dead path, failed, and marked the new engine failed (QAGUI-LIN 0213). The host now repairs before every component job and every load, and Control's update test start repoints such paths to its own folder (strata_control/control_paths.py).
57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
"""Paths a run config names inside a Control folder that no longer exists, pointed at this Control.
|
|
|
|
Setup writes absolute paths into a run config (``cwd``, ``--expert-profile``) that lie inside the Control it ran from. That folder can go away:
|
|
the Linux AppImage mounts its bundled Control at ``/tmp/.mount_<random>/usr/lib/Strata/control``, a new name at every start, and an app
|
|
reinstall or a Control update moves it too. A path that ends up inside a folder called ``control`` which no longer exists is pointed at the
|
|
same file in this Control when the file is there; any other value is left as it is. The app host does the same for the saved files
|
|
(apps/host/server/native-control.mjs ``repairControlPaths``); this is for a start that reads a run config itself (the update's test start).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import re
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
_INSIDE = re.compile(r"^(.+?[/\\]control)(?=[/\\]|$)(.*)$", re.IGNORECASE)
|
|
|
|
|
|
def this_control() -> Path:
|
|
"""The Control folder this code runs from (the folder that holds ``strata_control``)."""
|
|
return Path(__file__).resolve().parent.parent
|
|
|
|
|
|
def _same(a: str, b: Path) -> bool:
|
|
try:
|
|
return os.path.normcase(os.path.abspath(a)) == os.path.normcase(str(b.resolve()))
|
|
except OSError:
|
|
return False
|
|
|
|
|
|
def repoint_value(value: Any, here: Path | None = None) -> Any:
|
|
"""``value`` pointed at ``here`` (default: this Control) when it names a missing path inside another ``control`` folder; else unchanged."""
|
|
if not isinstance(value, str):
|
|
return value
|
|
m = _INSIDE.match(value)
|
|
if not m:
|
|
return value
|
|
here = here or this_control()
|
|
try:
|
|
if os.path.exists(value) or _same(m.group(1), here):
|
|
return value
|
|
except OSError:
|
|
return value
|
|
rest = m.group(2).lstrip("/\\")
|
|
candidate = here.joinpath(*re.split(r"[/\\]", rest)) if rest else here
|
|
return str(candidate) if candidate.exists() else value
|
|
|
|
|
|
def repoint(cfg: dict, here: Path | None = None) -> dict:
|
|
"""A copy of the run config with ``cwd`` and every ``args`` value repointed (see repoint_value)."""
|
|
out = dict(cfg)
|
|
if "cwd" in out:
|
|
out["cwd"] = repoint_value(out["cwd"], here)
|
|
if isinstance(out.get("args"), list):
|
|
out["args"] = [repoint_value(a, here) for a in out["args"]]
|
|
return out
|