mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-19 00:54:32 +01:00
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
62 lines
1.7 KiB
Python
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()
|