mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-20 22:52:35 +01:00
main.py became main/ with __main__.py, so the invocation string baked into
run.sh and the systemd unit (`python -m steam_backlog_enforcer.main`) stays
byte-identical and nothing needs redeploying. Commands are grouped into
sibling modules (status, install, picks, abandon, misc), with _shared.py as
a leaf holding the lock helpers and constants both need, and _registry.py
holding the command tables. main/__init__.py keeps every public and private
name importable, so `from steam_backlog_enforcer.main import X` is unchanged.
The subtle part is patch targets. The test suite builds them as
f"{PKG}.{name}", so a grep for the literal module path found nothing -- but
once a command moves to a submodule it resolves its dependencies from that
module's globals, and patching the main package's re-export silently stops
biting. Measured which of the 36 patched symbols moved: 8 could have passed
vacuously. Rather than repair PKG per class, the five test_main*.py files
(all cap violators anyway) were regrouped to mirror the production modules,
so each file has exactly one correct PKG. Verified by mutation: breaking a
line in status/misc/picks/_shared each makes the corresponding tests fail.
test_web_server.py patched main_mod.serve, which no longer intercepts
cmd_serve; repointed at main.misc and confirmed it fails when the call is
removed. Added tests for the __main__ shim, which coverage would otherwise
report at 0% under fail_under = 100.
Shared test builders live in tests/_main_helpers.py, reachable because the
Phase 0 name-tests-test exclude allows tests/_*.py.
1290 tests pass; every main/ module reports 100% coverage; `main`, `status`,
`bogus` and `--status` produce byte-identical output and exit codes to
pre-refactor. 55 -> 49 files over the cap.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPpmMpTSkp8UziRc5u8B7P
102 lines
3.6 KiB
Python
102 lines
3.6 KiB
Python
"""``status`` and ``list`` commands: read-only views of the current state."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from steam_backlog_enforcer._actions import (
|
|
active_manual_picks,
|
|
manual_pick_grace_remaining,
|
|
)
|
|
from steam_backlog_enforcer._total_block import get_total_block_status
|
|
from steam_backlog_enforcer.config import load_snapshot
|
|
from steam_backlog_enforcer.game_install import (
|
|
_echo,
|
|
get_installed_games,
|
|
is_protected_app,
|
|
)
|
|
from steam_backlog_enforcer.main._shared import _LIST_DISPLAY_LIMIT
|
|
from steam_backlog_enforcer.steam_api import GameInfo
|
|
from steam_backlog_enforcer.store_blocker import is_store_blocked
|
|
|
|
if TYPE_CHECKING:
|
|
from steam_backlog_enforcer.config import Config, State
|
|
|
|
|
|
def cmd_status(_config: Config, state: State) -> None:
|
|
"""Show current status."""
|
|
_echo("=== Steam Backlog Enforcer ===\n")
|
|
|
|
total_block = get_total_block_status()
|
|
if total_block.active:
|
|
_echo("*** TOTAL GAMING BLOCK ACTIVE ***")
|
|
if total_block.until is not None:
|
|
_echo(f"Blocked until: {total_block.until.strftime('%Y-%m-%d %H:%M UTC')}")
|
|
_echo(f"Days remaining: {total_block.days_remaining:.1f}\n")
|
|
|
|
if state.current_app_id:
|
|
_echo(
|
|
f"Assigned game: {state.current_game_name} (AppID={state.current_app_id})"
|
|
)
|
|
else:
|
|
_echo("No game currently assigned.")
|
|
|
|
_echo(f"Finished games: {len(state.finished_app_ids)}")
|
|
_echo(f"Store blocked: {is_store_blocked()}")
|
|
|
|
# Show installed games.
|
|
installed = get_installed_games()
|
|
real_games = [(aid, n) for aid, n in installed if not is_protected_app(aid)]
|
|
_echo(f"Installed games: {len(real_games)}")
|
|
|
|
if state.current_app_id:
|
|
is_assigned_installed = any(aid == state.current_app_id for aid, _ in installed)
|
|
_echo(f"Assigned game installed: {is_assigned_installed}")
|
|
|
|
picks = active_manual_picks(state)
|
|
if picks:
|
|
_echo(f"\nManual picks ({len(picks)}):")
|
|
for pick in picks:
|
|
grace = manual_pick_grace_remaining(state, pick["app_id"])
|
|
undo = (
|
|
f" — undoable for {grace:.1f} more day(s)"
|
|
if grace is not None and grace > 0
|
|
else ""
|
|
)
|
|
_echo(f" {pick['game_name']} (AppID={pick['app_id']}){undo}")
|
|
_echo("\n[MANUAL PICK LOCK is active — most commands are blocked]")
|
|
|
|
|
|
def cmd_list(_config: Config, state: State) -> None:
|
|
"""List games from the last snapshot."""
|
|
snapshot = load_snapshot()
|
|
if snapshot is None:
|
|
_echo("No snapshot found. Run 'scan' first.")
|
|
return
|
|
|
|
games = [GameInfo.from_snapshot(d) for d in snapshot]
|
|
incomplete = [g for g in games if not g.is_complete]
|
|
complete = [g for g in games if g.is_complete]
|
|
|
|
# Sort incomplete by completionist hours.
|
|
def sort_key(g: GameInfo) -> tuple[int, float]:
|
|
if g.completionist_hours > 0:
|
|
return (0, g.completionist_hours)
|
|
return (1, 0.0)
|
|
|
|
incomplete.sort(key=sort_key)
|
|
|
|
_echo(f"\n{'─' * 70}")
|
|
_echo(f" INCOMPLETE ({len(incomplete)} games)")
|
|
_echo(f"{'─' * 70}")
|
|
for i, g in enumerate(incomplete[:_LIST_DISPLAY_LIMIT], 1):
|
|
marker = " <<< ASSIGNED" if g.app_id == state.current_app_id else ""
|
|
hrs = f" [{g.completionist_hours:.0f}h]" if g.completionist_hours > 0 else ""
|
|
pct = f"{g.completion_pct:.0f}%"
|
|
_echo(f" {i:3d}. {g.name[:40]:<40s} {pct:>5s}{hrs}{marker}")
|
|
|
|
if len(incomplete) > _LIST_DISPLAY_LIMIT:
|
|
_echo(f" ... and {len(incomplete) - _LIST_DISPLAY_LIMIT} more")
|
|
|
|
_echo(f"\n COMPLETE: {len(complete)} games")
|