feat(l4d2): implement callback-aware install command
This commit is contained in:
parent
60de361706
commit
3c92721973
2 changed files with 72 additions and 0 deletions
37
components/l4d2-host-lib/src/l4d2host/steam_install.py
Normal file
37
components/l4d2-host-lib/src/l4d2host/steam_install.py
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Callable
|
||||||
|
|
||||||
|
from l4d2host.process import run_command
|
||||||
|
|
||||||
|
|
||||||
|
class SteamInstaller:
|
||||||
|
def __init__(self, install_dir: Path = Path("/opt/l4d2/installation"), steamcmd: str = "steamcmd"):
|
||||||
|
self.install_dir = install_dir
|
||||||
|
self.steamcmd = steamcmd
|
||||||
|
|
||||||
|
def install_or_update(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
on_stdout: Callable[[str], None] | None = None,
|
||||||
|
on_stderr: Callable[[str], None] | None = None,
|
||||||
|
passthrough: bool = False,
|
||||||
|
) -> None:
|
||||||
|
for platform in ("windows", "linux"):
|
||||||
|
run_command(
|
||||||
|
[
|
||||||
|
self.steamcmd,
|
||||||
|
"+force_install_dir",
|
||||||
|
str(self.install_dir),
|
||||||
|
"+login",
|
||||||
|
"anonymous",
|
||||||
|
"+@sSteamCmdForcePlatformType",
|
||||||
|
platform,
|
||||||
|
"+app_update",
|
||||||
|
"222860",
|
||||||
|
"validate",
|
||||||
|
"+quit",
|
||||||
|
],
|
||||||
|
on_stdout=on_stdout,
|
||||||
|
on_stderr=on_stderr,
|
||||||
|
passthrough=passthrough,
|
||||||
|
)
|
||||||
35
components/l4d2-host-lib/tests/test_install.py
Normal file
35
components/l4d2-host-lib/tests/test_install.py
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from l4d2host.steam_install import SteamInstaller
|
||||||
|
|
||||||
|
|
||||||
|
def test_windows_then_linux(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
|
calls: list[list[str]] = []
|
||||||
|
|
||||||
|
def fake_run_command(cmd, **kwargs):
|
||||||
|
del kwargs
|
||||||
|
calls.append(list(cmd))
|
||||||
|
|
||||||
|
monkeypatch.setattr("l4d2host.steam_install.run_command", fake_run_command)
|
||||||
|
SteamInstaller().install_or_update()
|
||||||
|
assert "windows" in calls[0]
|
||||||
|
assert "linux" in calls[1]
|
||||||
|
|
||||||
|
|
||||||
|
def test_fail_fast_on_first_failure(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
|
calls: list[list[str]] = []
|
||||||
|
|
||||||
|
def fake_run_command(cmd, **kwargs):
|
||||||
|
del kwargs
|
||||||
|
calls.append(list(cmd))
|
||||||
|
if len(calls) == 1:
|
||||||
|
raise subprocess.CalledProcessError(returncode=1, cmd=cmd)
|
||||||
|
|
||||||
|
monkeypatch.setattr("l4d2host.steam_install.run_command", fake_run_command)
|
||||||
|
|
||||||
|
with pytest.raises(subprocess.CalledProcessError):
|
||||||
|
SteamInstaller().install_or_update()
|
||||||
|
|
||||||
|
assert len(calls) == 1
|
||||||
Loading…
Reference in a new issue