ctf_status.py is now just the command line; the work lives in tracker/. The rules that decide whether a challenge is believed are in tracker/checks.py, one function per rule, listed in README_CHECKS and REPO_CHECKS. Output is unchanged. Read the config from .env only (ctf_status.env.example -> .env.example), let single_run_lock() hold its own lock files, and rewrite the README as a short overview of what the repo does and how to run it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
"""Config from .env next to ctf_status.py; environment variables override it."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
CFG_KEYS = ("GITLAB_GROUP_URL", "GITLAB_TOKEN")
|
|
OPT_KEYS = ("HEDGEDOC_NOTE", "HEDGEDOC_TAGS", "TITLE",
|
|
"CHALLS_REPO_URL", "CHALLS_PATH", "CHALLS_BRANCH")
|
|
# the names a plain `.env` tends to use for the same thing
|
|
ALIASES = {"GL_PAT": "GITLAB_TOKEN", "GITLAB_URL": "GITLAB_GROUP_URL"}
|
|
DEFAULT_TAGS = "Logistics, h4tum CTF 2026"
|
|
DEFAULT_TITLE = "CTF challenge tracking"
|
|
DEFAULT_CHALLS_PATH = "2026/challs.txt"
|
|
|
|
|
|
def load_env() -> dict:
|
|
cfg = {}
|
|
env_file = Path(__file__).parent.parent / ".env" # the repo, next to ctf_status.py
|
|
if env_file.exists():
|
|
for line in env_file.read_text().splitlines():
|
|
line = line.strip()
|
|
if not line or line.startswith("#") or "=" not in line:
|
|
continue
|
|
k, v = line.split("=", 1)
|
|
k = k.strip().upper()
|
|
cfg.setdefault(ALIASES.get(k, k), v.strip().strip("'\""))
|
|
for k in CFG_KEYS + OPT_KEYS + tuple(ALIASES):
|
|
if os.environ.get(k):
|
|
cfg[ALIASES.get(k, k)] = os.environ[k]
|
|
missing = [k for k in CFG_KEYS if not cfg.get(k)]
|
|
if missing:
|
|
sys.exit(f"missing config: {', '.join(missing)} (see .env.example)")
|
|
return cfg
|