50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
"""Application-local runtime; a bundle never falls back to tools on PATH."""
|
|
from __future__ import annotations
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
PRODUCT = "YouTubeDL.Helper"
|
|
|
|
|
|
def manifest():
|
|
path = ROOT / "bundle.json"
|
|
if not path.is_file():
|
|
return None
|
|
value = json.loads(path.read_text(encoding="utf-8"))
|
|
if value.get("product") != PRODUCT or value.get("mode") != "autonomous":
|
|
raise ValueError("Повреждён комплект помощника. Повторите установку.")
|
|
return value
|
|
|
|
|
|
def executable(name):
|
|
bundle = manifest()
|
|
if not bundle:
|
|
return None
|
|
relative = bundle.get("tools", {}).get(name)
|
|
if not isinstance(relative, str):
|
|
raise ValueError(f"В комплекте отсутствует {name}. Повторите установку помощника.")
|
|
candidate = (ROOT / relative).resolve()
|
|
if ROOT not in candidate.parents or not candidate.is_file():
|
|
raise ValueError(f"Встроенный {name} повреждён. Повторите установку помощника.")
|
|
return str(candidate)
|
|
|
|
|
|
def installation_root():
|
|
# The installer puts each complete release under <application>/releases/<id>.
|
|
if manifest() and ROOT.parent.name == "releases":
|
|
return ROOT.parent.parent
|
|
return None
|
|
|
|
|
|
def history_path():
|
|
installed = installation_root()
|
|
return (installed / "data" if installed else ROOT / ".runtime") / "completed-jobs.json"
|
|
|
|
|
|
def information():
|
|
bundle = manifest()
|
|
return {"mode": "autonomous" if bundle else "source", "version": bundle.get("version") if bundle else None,
|
|
"updateTogether": bool(bundle)}
|