Initial Robot U site prototype
This commit is contained in:
commit
fe19f200d7
27 changed files with 3677 additions and 0 deletions
48
settings.py
Normal file
48
settings.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Settings:
|
||||
forgejo_base_url: str
|
||||
forgejo_token: str | None
|
||||
forgejo_repo_scan_limit: int
|
||||
forgejo_recent_issue_limit: int
|
||||
forgejo_request_timeout_seconds: float
|
||||
calendar_feed_urls: tuple[str, ...]
|
||||
calendar_event_limit: int
|
||||
|
||||
|
||||
def _normalize_base_url(raw_value: str | None) -> str:
|
||||
value = (raw_value or "").strip()
|
||||
if not value:
|
||||
return "https://aksal.cloud"
|
||||
if value.startswith(("http://", "https://")):
|
||||
return value.rstrip("/")
|
||||
return f"https://{value.rstrip('/')}"
|
||||
|
||||
|
||||
def _parse_calendar_feed_urls(raw_value: str | None) -> tuple[str, ...]:
|
||||
value = (raw_value or "").strip()
|
||||
if not value:
|
||||
return ()
|
||||
|
||||
return tuple(entry.strip() for entry in value.replace("\n", ",").split(",") if entry.strip())
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_settings() -> Settings:
|
||||
return Settings(
|
||||
forgejo_base_url=_normalize_base_url(os.getenv("FORGEJO_BASE_URL")),
|
||||
forgejo_token=os.getenv("FORGEJO_TOKEN") or None,
|
||||
forgejo_repo_scan_limit=int(os.getenv("FORGEJO_REPO_SCAN_LIMIT", "30")),
|
||||
forgejo_recent_issue_limit=int(os.getenv("FORGEJO_RECENT_ISSUE_LIMIT", "6")),
|
||||
forgejo_request_timeout_seconds=float(
|
||||
os.getenv("FORGEJO_REQUEST_TIMEOUT_SECONDS", "10.0"),
|
||||
),
|
||||
calendar_feed_urls=_parse_calendar_feed_urls(os.getenv("CALENDAR_FEED_URLS")),
|
||||
calendar_event_limit=int(os.getenv("CALENDAR_EVENT_LIMIT", "6")),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue