38 lines
1.6 KiB
Python
38 lines
1.6 KiB
Python
"""Verify and register an unpacked offline bundle. Never downloads anything."""
|
|
from __future__ import annotations
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from host.bundle import ROOT, executable, manifest
|
|
from host.common import EXTENSION_ID, HOST_NAME
|
|
from host.dependencies import status
|
|
|
|
|
|
def verify():
|
|
if not manifest():
|
|
raise ValueError("Autonomous bundle metadata is missing.")
|
|
if Path(sys.executable).resolve() != Path(executable("python")):
|
|
raise ValueError("The helper must use its embedded Python.")
|
|
measured = status()
|
|
if any(item["status"] != "installed" for item in measured):
|
|
raise ValueError("Bundled components failed verification: " + json.dumps(measured))
|
|
print(json.dumps({"ready": True, "dependencies": measured}))
|
|
|
|
|
|
def configure():
|
|
verify()
|
|
runtime = ROOT / ".runtime"
|
|
runtime.mkdir(exist_ok=True)
|
|
python = executable("python")
|
|
launcher = runtime / "launch-host.cmd"
|
|
launcher.write_bytes((f'@echo off\r\nchcp 65001 >nul\r\nset PYTHONIOENCODING=utf-8\r\nset PYTHONUTF8=1\r\n'
|
|
f'set PYTHONDONTWRITEBYTECODE=1\r\n"{python}" -I -X utf8 -B -u "{ROOT / "host" / "main.py"}" %*\r\n').encode("utf-8"))
|
|
native = {"name": HOST_NAME, "description": "YouTubeDL autonomous helper", "path": str(launcher),
|
|
"type": "stdio", "allowed_origins": [f"chrome-extension://{EXTENSION_ID}/"]}
|
|
(runtime / "native-host.json").write_text(json.dumps(native, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
configure() if sys.argv[1:] == ["configure"] else verify()
|