utils/sickdays/sickdays/_paths.py
Krzysztof kuhy Rudnicki 894d76f811 sickdays 0.1.0 + earned_time 0.11.0: uncapped sick-day pool, 20:00 sick shutdown floor
sickdays: per-date pool, no cap or reason, add/remove today or later only,
import_legacy for the migration. LWW state flip per date (no tombstones),
Firebase RTDB sickdays-sync/devices/<uuid>/sick_days.json, HMAC audit trail.
Readers fail closed (unreadable pool = not sick, logged); writers refuse a
corrupt pool. Free-day cross-check via a lazily imported freedays predicate.

earned_time: resolve(..., sick=True) floors the final shutdown at 20:00
(capped at the ceiling); gaming, terms and base unchanged. Result dataclasses
moved to _resolution.py for the line cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xfj1sxKH9VBPqpcAni8Jry
2026-10-16 08:23:00 +02:00

62 lines
1.7 KiB
Python

# Copyright (c) 2026 Krzysztof Rudnicki
"""Every file this package owns, as one value that can be swapped wholesale.
The same seam freedays uses: one bundle, so ``Paths.under(tmp_path)``
redirects everything at once and a file added to this class later is
redirected by construction rather than by remembering to update a list.
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING
from sickdays._constants import (
AUDIT_PATH,
DEVICE_ID_PATH,
HMAC_KEY_FILE,
LOG_PATH,
SYNC_STATE_PATH,
)
if TYPE_CHECKING:
from pathlib import Path
@dataclass(frozen=True)
class Paths:
"""Where the pool, the device id, the audit trail and sync state live."""
log: Path
device_id: Path
audit: Path
hmac_key: Path
sync_state: Path
@classmethod
def default(cls) -> Paths:
"""The real, per-user locations under ``~/.local/share/sickdays``."""
return cls(
log=LOG_PATH,
device_id=DEVICE_ID_PATH,
audit=AUDIT_PATH,
hmac_key=HMAC_KEY_FILE,
sync_state=SYNC_STATE_PATH,
)
@classmethod
def under(cls, directory: Path) -> Paths:
"""Every file, relocated under ``directory``. The test seam."""
return cls(
log=directory / "sick_days.json",
device_id=directory / "device_id",
audit=directory / "audit.jsonl",
hmac_key=directory / "hmac.key",
sync_state=directory / "sync_state.json",
)
def resolve_paths(paths: Paths | None) -> Paths:
"""Return ``paths``, or the real locations when it is ``None``."""
return paths if paths is not None else Paths.default()