2024-01-04 15:43:40 +00:00
|
|
|
import toml
|
|
|
|
import logging
|
2024-02-07 16:53:29 +00:00
|
|
|
import subprocess
|
2024-01-04 15:43:40 +00:00
|
|
|
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,
|
|
|
|
check=True
|
|
|
|
).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"
|
|
|
|
|
2024-01-04 15:43:40 +00:00
|
|
|
try:
|
|
|
|
CONFIG = toml.load('config.toml')
|
2024-01-06 21:43:52 +00:00
|
|
|
CONFIG.setdefault("logging", {})
|
|
|
|
CONFIG.setdefault("jimmy", {})
|
|
|
|
CONFIG.setdefault("ollama", {})
|
2024-02-28 18:17:55 +00:00
|
|
|
CONFIG.setdefault("rss", {"meta": {"channel": None}})
|
2024-01-09 16:26:18 +00:00
|
|
|
CONFIG.setdefault(
|
|
|
|
"server",
|
|
|
|
{
|
|
|
|
"host": "0.0.0.0",
|
|
|
|
"port": 8080,
|
|
|
|
"channel": 1032974266527907901
|
|
|
|
}
|
|
|
|
)
|
2024-01-12 16:47:45 +00:00
|
|
|
CONFIG.setdefault(
|
|
|
|
"redis",
|
|
|
|
{
|
|
|
|
"host": "redis",
|
|
|
|
"port": 6379,
|
|
|
|
"decode_responses": True
|
|
|
|
}
|
|
|
|
)
|
2024-01-04 15:43:40 +00:00
|
|
|
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)
|
2024-01-04 15:43:40 +00:00
|
|
|
raise
|