move bumpversion to pyproject, update workflow, add database configuration to config class

This commit is contained in:
2025-05-29 11:28:55 +02:00
parent c9d6d5de8f
commit 40d6e8824e
4 changed files with 72 additions and 37 deletions

View File

@@ -1,13 +1,48 @@
from dataclasses import dataclass
from typing import List, Optional
from typing import List, Optional, Union
import os
from omegaconf import OmegaConf, DictConfig
from pathlib import Path
from komconfig import CONFIG_PATH
from urllib.parse import quote_plus
SETTINGS_PATH = os.path.join(CONFIG_PATH, "config.yaml")
@dataclass
class RemoteSettings:
url: str
port: int
user: str
password: str
database_name: str = "komcache"
@dataclass
class Cache:
mode: str
remote: dict[str, Union[str, int]] |RemoteSettings
local_path: str | Path
def __post__init__(self):
if self.mode == "remote":
self.remote = RemoteSettings(**self.remote)
else:
self.remote = None
self.local_path = Path(self.local_path).expanduser()
@property
def path(self):
if self.mode == "local":
return Path(self.local_path).expanduser()
else:
return f"{self.remote.url}:{self.remote.port}"
@property
def url(self):
password = quote_plus(self.remote.password) if self.remote else ""
return f"mysql+pymysql://{self.remote.user}:{password}@{self.remote.url}:{self.remote.port}/{self.remote.database_name}"
@dataclass
class Komga:
"""Komga server settings."""
@@ -328,6 +363,10 @@ class Settings:
@property
def komtagger(self):
return KomTagger(**self._config.komtagger)
@property
def cache(self):
return Cache(**self._config.cache)
def komtagger_attr(self, name):
return getattr(self.komtagger, name)