mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-22 23:02:19 +01:00
The installer ships as the steam_installer package beside steam_backlog_enforcer, with its tests, docs and Proton lock. The enforcer's fast install now starts the installer from this checkout. Both appinfo.vdf readers share one key-value decoder (steam_installer.appinfo_kv), and the duplicated test fixtures and helpers are folded into conftest and _cli_helpers so the whole-tree duplicate-code check is clean. check_requirements_sync treats sibling packages as first-party. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZCxnNWLtpVwFLVk9w
76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
"""How the installer (``steam_installer``) is invoked: where, as whom, what argv.
|
|
|
|
Split out of :mod:`_fast_install`, which runs and reaps the installer; this
|
|
half only decides the command line, every choice it would otherwise prompt for
|
|
pinned in advance.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import re
|
|
|
|
from steam_backlog_enforcer._desktop_env import desktop_user_cmd
|
|
from steam_backlog_enforcer._steam_state import STEAMAPPS_PATH
|
|
|
|
# The installer ships in this repo (``steam_installer``, a sibling package).
|
|
# Tests repoint this at a missing file: it always exists here, and a real run
|
|
# closes the user's Steam.
|
|
_INSTALLER = Path(__file__).resolve().parents[1] / "steam_installer" / "cli.py"
|
|
|
|
# The interpreter the daemon itself runs under (see the unit's ExecStart). The
|
|
# installer needs ``kuhy_credit``, which lives in the desktop user's site.
|
|
_PYTHON = "/usr/bin/python3"
|
|
|
|
# Depot content only: the app itself is ours to choose, the language is not
|
|
# worth a prompt nobody is there to answer.
|
|
_LANGUAGE = "english"
|
|
|
|
|
|
def installer_path() -> Path | None:
|
|
"""The installer's ``cli.py`` inside this checkout, if present.
|
|
|
|
A checkout is the same for every user, so unlike the old external clone
|
|
there is no per-user lookup.
|
|
"""
|
|
return _INSTALLER if _INSTALLER.is_file() else None
|
|
|
|
|
|
def steam_account_name() -> str | None:
|
|
"""The account Steam itself last signed in with, from ``loginusers.vdf``.
|
|
|
|
Read from Steam's own state rather than a copy in the enforcer config, so
|
|
it cannot drift from the account that actually owns the games.
|
|
"""
|
|
path = STEAMAPPS_PATH.parent / "config" / "loginusers.vdf"
|
|
try:
|
|
content = path.read_text(encoding="utf-8", errors="replace")
|
|
except OSError:
|
|
return None
|
|
match = re.search(r'"AccountName"\s+"([^"]+)"', content)
|
|
return match.group(1) if match else None
|
|
|
|
|
|
def build_cmd(installer: Path, app_id: int, user: str | None) -> list[str]:
|
|
"""The installer invocation, dropped to the desktop user when root.
|
|
|
|
Launched as ``python3 -m steam_installer.cli`` with the checkout on
|
|
``PYTHONPATH``: ``sudo`` resets the environment, so it is named in the argv.
|
|
"""
|
|
cmd = [
|
|
"env",
|
|
f"PYTHONPATH={installer.parents[1]}",
|
|
_PYTHON,
|
|
"-m",
|
|
"steam_installer.cli",
|
|
"--appid",
|
|
str(app_id),
|
|
"--yes",
|
|
"--language",
|
|
_LANGUAGE,
|
|
]
|
|
account = steam_account_name()
|
|
if account:
|
|
cmd += ["--username", account]
|
|
return desktop_user_cmd(cmd, user)
|