Fix logging and versioning
This commit is contained in:
@@ -30,31 +30,31 @@ def _load_toml(path: Path) -> dict:
|
||||
with path.open("rb") as f:
|
||||
return tomllib.load(f)
|
||||
except FileNotFoundError:
|
||||
_fatal(f"[FATL] Configuration file not found at {path}")
|
||||
_fatal(f"Configuration file not found at {path}")
|
||||
except PermissionError:
|
||||
_fatal(f"[FATL] Permission denied when accessing configuration {path}")
|
||||
_fatal(f"Permission denied when accessing configuration {path}")
|
||||
except tomllib.TOMLDecodeError as e:
|
||||
_fatal(f"[FATL] Invalid TOML configuration: {e}")
|
||||
_fatal(f"Invalid TOML configuration: {e}")
|
||||
|
||||
|
||||
def _read_signing_key_from_path(path_value) -> str | None:
|
||||
p = Path(path_value)
|
||||
if not p.exists():
|
||||
_fatal(f"[FATL] signing_key_path {p} does not exist")
|
||||
_fatal(f"signing_key_path {p} does not exist")
|
||||
try:
|
||||
return p.read_text(encoding="utf-8").strip()
|
||||
except Exception as e:
|
||||
_fatal(f"[FATL] Failed to read signing_key_path {p}: {e}")
|
||||
_fatal(f"Failed to read signing_key_path {p}: {e}")
|
||||
|
||||
|
||||
def _validate_cat_path(cat_path: str) -> Path:
|
||||
p = Path(cat_path)
|
||||
if not p.exists():
|
||||
_fatal(f"[FATL] Cat photo at {p} does not exist")
|
||||
_fatal(f"Cat photo at {p} does not exist")
|
||||
|
||||
mtype, _ = mimetypes.guess_type(str(p))
|
||||
if mtype is None or not mtype.startswith("image/"):
|
||||
_warn(f"[WARN] Cat file {p} does not look like an image (mimetype={mtype})")
|
||||
_warn(f"Cat file {p} does not look like an image (mimetype={mtype})")
|
||||
|
||||
return p
|
||||
|
||||
@@ -69,9 +69,7 @@ def _apply_config(cfg: dict) -> None:
|
||||
try:
|
||||
port = int(cfg["port"])
|
||||
except (TypeError, ValueError):
|
||||
_warn(
|
||||
f"[WARN] Invalid port in config: {cfg.get('port')}; using default {port}"
|
||||
)
|
||||
_warn(f"Invalid port in config: {cfg.get('port')}; using default {port}")
|
||||
|
||||
if "allow_registration" in cfg:
|
||||
allow_registration = bool(cfg["allow_registration"])
|
||||
@@ -79,12 +77,10 @@ def _apply_config(cfg: dict) -> None:
|
||||
if "server_name" in cfg:
|
||||
server_name = str(cfg["server_name"])
|
||||
else:
|
||||
_fatal("[FATL] `server_name` is not in configuration")
|
||||
_fatal("`server_name` is not in configuration")
|
||||
|
||||
if "signing_key" in cfg and "signing_key_path" in cfg:
|
||||
_warn(
|
||||
"[WARN] Both `signing_key` and `signing_key_path` present. Using `signing_key`."
|
||||
)
|
||||
_warn("Both `signing_key` and `signing_key_path` present. Using `signing_key`.")
|
||||
|
||||
if "signing_key" in cfg:
|
||||
signing_key = str(cfg["signing_key"]).strip()
|
||||
@@ -94,7 +90,7 @@ def _apply_config(cfg: dict) -> None:
|
||||
signing_key = sk
|
||||
else:
|
||||
_fatal(
|
||||
"[FATL] `signing_key` is not in configuration. "
|
||||
"`signing_key` is not in configuration. "
|
||||
"A signing key can be generated using `cmd/generate_key.py`."
|
||||
)
|
||||
|
||||
@@ -115,7 +111,7 @@ def _apply_config(cfg: dict) -> None:
|
||||
if len(contact) > 1:
|
||||
support_obj["contacts"].append(contact)
|
||||
else:
|
||||
_warn("[WARN] No support contacts are defined")
|
||||
_warn("No support contacts are defined")
|
||||
support = support_obj
|
||||
|
||||
print("[INFO] Configuration file was valid")
|
||||
|
||||
@@ -1 +1 @@
|
||||
import vona.config
|
||||
import vona.config
|
||||
|
||||
Reference in New Issue
Block a user