college-bot-v2/src/conf.py

39 lines
1.3 KiB
Python
Raw Normal View History

import toml
import logging
2024-02-07 16:53:29 +00:00
import subprocess
from pathlib import Path
2024-02-07 16:53:29 +00:00
log = logging.getLogger("jimmy.autoconf")
if (Path.cwd() / ".git").exists():
try:
log.debug("Attempting to auto-detect running version using git.")
VERSION = subprocess.run(
["git", "rev-parse", "--short", "HEAD"],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
text=True,
2024-04-16 00:46:26 +01:00
check=True,
2024-02-07 16:53:29 +00:00
).stdout.strip()
except subprocess.CalledProcessError:
log.debug("Unable to auto-detect running version using git.", exc_info=True)
VERSION = "unknown"
else:
log.debug("Unable to auto-detect running version using git, no .git directory exists.")
VERSION = "unknown"
try:
2024-04-16 00:46:26 +01:00
CONFIG = toml.load("config.toml")
CONFIG.setdefault("logging", {})
CONFIG.setdefault("jimmy", {})
CONFIG.setdefault("ollama", {})
2024-02-28 18:17:55 +00:00
CONFIG.setdefault("rss", {"meta": {"channel": None}})
CONFIG.setdefault("screenshot", {})
2024-03-18 23:59:46 +00:00
CONFIG.setdefault("quote_a", {"channel": None})
2024-04-16 00:46:26 +01:00
CONFIG.setdefault("server", {"host": "0.0.0.0", "port": 8080, "channel": 1032974266527907901})
CONFIG.setdefault("redis", {"host": "redis", "port": 6379, "decode_responses": True})
except FileNotFoundError:
cwd = Path.cwd()
2024-02-07 16:53:29 +00:00
log.critical("Unable to locate config.toml in %s.", cwd, exc_info=True)
raise