mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-21 12:32:24 +01:00
Kuhy removed the daily gaming/leisure budget; only shutdown time (screen-locker) stays. One gate, _gaming_gate.gaming_enforced_on(day), wraps earned_time 0.22.0 gaming_enforced; resolve_budget carries it as BudgetResolution.enforced and rules_for as PlaytimeRules.gaming_enforced. Unlimited day: no warning, no cutoff, no kill, no leisure billing or leisure kill; a block left from an earlier day is lifted. Time is still billed for history. Backlog game choice and launch scope are untouched. MCP, CLI and /api/budget report unlimited with null numbers; the web UI paints the no-cap icon, no meter. Past-day history keeps working. Failure modes: switch unreadable or day key not a date -> fail OPEN (unlimited), logged ERROR once per cause, never raises, so the 5 h fallback is never enforced and the daemon never crashes. Demo runs stay enforced. The playtime_state.json schema is unchanged. Pins earned-time-v0.22.0 and leisure-watch-v0.2.8 (freshness gate; only golive.py changed, procscan untouched). DOCS-web-control-api notes null fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWViGJJaqBKGr1Hbppr
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
"""Why the budget state file did or did not open, for the budget view.
|
|
|
|
Split from :mod:`_budget_view` (250-line cap); that module re-exports every name.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Final
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
READABLE: Final = "ok"
|
|
MISSING: Final = "missing"
|
|
DENIED: Final = "denied"
|
|
CORRUPT: Final = "corrupt"
|
|
|
|
STATUS_MESSAGES: Final[dict[str, str]] = {
|
|
DENIED: (
|
|
"Cannot read the budget state file. It is owned by root, and only "
|
|
"becomes world-readable once the enforcer has rewritten it — restart "
|
|
"steam-backlog-enforcer.service."
|
|
),
|
|
MISSING: "No gaming time has been recorded yet today.",
|
|
CORRUPT: (
|
|
"The budget state file could not be parsed. The enforcer treats that "
|
|
"as tampering and will start the day fail-closed."
|
|
),
|
|
}
|
|
|
|
|
|
def state_access(path: Path) -> str:
|
|
"""Classify why the state file did or did not open.
|
|
|
|
``load_state`` deliberately collapses "missing", "corrupt" and "unreadable"
|
|
into ``None`` — its caller is the enforcer, whose recovery is the same for
|
|
all three. A display needs to tell them apart, because "you have not gamed
|
|
today" and "I am not allowed to look" are opposite messages.
|
|
|
|
The read is attempted rather than pre-checked with ``os.access``: the
|
|
kernel's answer to the actual open is the only one that cannot disagree
|
|
with what ``load_state`` just experienced. The file is a couple of hundred
|
|
bytes, so reading it twice costs nothing.
|
|
|
|
Args:
|
|
path: The state file.
|
|
|
|
Returns:
|
|
``READABLE``, ``MISSING`` or ``DENIED``.
|
|
"""
|
|
try:
|
|
path.read_bytes()
|
|
except FileNotFoundError:
|
|
return MISSING
|
|
except OSError:
|
|
return DENIED
|
|
return READABLE
|