2025-06-12 19:21:58 +02:00
|
|
|
|
from os import path
|
2025-06-04 20:18:03 +02:00
|
|
|
|
from pathlib import Path
|
2025-06-12 19:21:58 +02:00
|
|
|
|
from sys import platform
|
2025-06-13 20:23:19 +02:00
|
|
|
|
from typing import Tuple, Type
|
2025-06-04 20:18:03 +02:00
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel
|
2025-06-13 20:23:19 +02:00
|
|
|
|
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource, SettingsConfigDict, JsonConfigSettingsSource
|
2025-06-12 19:21:58 +02:00
|
|
|
|
|
|
|
|
|
|
app_name = "DocuMentor"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if platform == "win32":
|
|
|
|
|
|
config_path = f"%APPDATA%\\{app_name}\\config.json"
|
2025-06-13 20:23:19 +02:00
|
|
|
|
elif platform in ("linux", "linux2"):
|
2025-06-12 19:21:58 +02:00
|
|
|
|
config_path = f"~/.config/{app_name}/config.json"
|
|
|
|
|
|
elif platform == "darwin":
|
|
|
|
|
|
config_path = f"~/Library/Application Support/{app_name}/͏͏͏͏config.json"
|
|
|
|
|
|
else:
|
|
|
|
|
|
config_path = f"~/.config/{app_name}/config.json"
|
|
|
|
|
|
|
|
|
|
|
|
config_path = Path(path.expandvars(config_path))
|
2025-06-04 20:18:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class JavaVm(BaseModel):
|
2025-06-09 19:50:17 +02:00
|
|
|
|
id: int
|
2025-06-06 20:18:29 +02:00
|
|
|
|
version: str
|
2025-06-04 20:18:03 +02:00
|
|
|
|
path_to_binary_file: Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DiffPdf(BaseModel):
|
2025-06-09 19:50:17 +02:00
|
|
|
|
id: int
|
2025-06-06 20:18:29 +02:00
|
|
|
|
version: str
|
2025-06-04 20:18:03 +02:00
|
|
|
|
path_to_binary_file: Path
|
|
|
|
|
|
default_params: list[str]
|
2025-06-06 20:18:29 +02:00
|
|
|
|
output_file_extension: str = "pdf"
|
2025-06-04 20:18:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SaxonJar(BaseModel):
|
2025-06-09 19:50:17 +02:00
|
|
|
|
id: int
|
2025-06-06 20:18:29 +02:00
|
|
|
|
version: str
|
2025-06-04 20:18:03 +02:00
|
|
|
|
path_to_jar_file: Path
|
2025-06-06 20:18:29 +02:00
|
|
|
|
output_file_extension: str = "fo"
|
2025-06-04 20:18:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ApacheFop(BaseModel):
|
2025-06-09 19:50:17 +02:00
|
|
|
|
id: int
|
2025-06-06 20:18:29 +02:00
|
|
|
|
version: str
|
2025-06-04 20:18:03 +02:00
|
|
|
|
path_to_dir: Path
|
2025-06-06 20:18:29 +02:00
|
|
|
|
output_file_extension: str = "pdf"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class XslDir(BaseModel):
|
2025-06-09 19:50:17 +02:00
|
|
|
|
id: int
|
2025-06-06 20:18:29 +02:00
|
|
|
|
name: str
|
|
|
|
|
|
path_to_root_dir: Path
|
2025-06-06 20:32:23 +02:00
|
|
|
|
|
2025-06-04 20:18:03 +02:00
|
|
|
|
|
2025-06-06 20:18:29 +02:00
|
|
|
|
class PdfProject(BaseModel):
|
2025-06-09 19:50:17 +02:00
|
|
|
|
id: int
|
2025-06-04 20:18:03 +02:00
|
|
|
|
name: str
|
|
|
|
|
|
project_dir: Path
|
2025-06-09 19:58:24 +02:00
|
|
|
|
java_vm_id: int
|
2025-06-09 19:50:17 +02:00
|
|
|
|
diff_pdf_id: int
|
|
|
|
|
|
saxon_jar_id: int
|
|
|
|
|
|
apache_fop_id: int
|
|
|
|
|
|
xsl_dir_id: int
|
2025-06-06 20:18:29 +02:00
|
|
|
|
default_xslt_params: dict[str, str] = {}
|
2025-06-04 20:18:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AppSettings(BaseSettings):
|
2025-06-12 19:21:58 +02:00
|
|
|
|
java_vms: list[JavaVm] = []
|
|
|
|
|
|
diff_pdfs: list[DiffPdf] = []
|
|
|
|
|
|
saxon_jars: list[SaxonJar] = []
|
|
|
|
|
|
apache_fops: list[ApacheFop] = []
|
|
|
|
|
|
xsl_dirs: list[XslDir] = []
|
2025-06-06 20:18:29 +02:00
|
|
|
|
pdf_projects: list[PdfProject] = []
|
2025-06-06 20:32:23 +02:00
|
|
|
|
|
2025-06-12 19:21:58 +02:00
|
|
|
|
model_config = SettingsConfigDict(json_file=config_path)
|
2025-06-13 20:23:19 +02:00
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def settings_customise_sources(
|
|
|
|
|
|
cls,
|
|
|
|
|
|
settings_cls: Type[BaseSettings],
|
|
|
|
|
|
init_settings: PydanticBaseSettingsSource,
|
|
|
|
|
|
env_settings: PydanticBaseSettingsSource,
|
|
|
|
|
|
dotenv_settings: PydanticBaseSettingsSource,
|
|
|
|
|
|
file_secret_settings: PydanticBaseSettingsSource,
|
|
|
|
|
|
) -> Tuple[PydanticBaseSettingsSource, ...]:
|
|
|
|
|
|
return (JsonConfigSettingsSource(settings_cls),)
|
|
|
|
|
|
|
2025-06-12 20:43:31 +02:00
|
|
|
|
def save(self):
|
|
|
|
|
|
global config_path
|
2025-06-13 20:23:19 +02:00
|
|
|
|
if not config_path.parent.exists():
|
|
|
|
|
|
# Ordner existert nicht
|
|
|
|
|
|
config_path.parent.mkdir(parents=True, exist_ok=True)
|
2025-06-12 19:21:58 +02:00
|
|
|
|
|
2025-06-13 20:23:19 +02:00
|
|
|
|
# Konfiguration speichern
|
|
|
|
|
|
with open(config_path, "wb") as c:
|
|
|
|
|
|
c.write(app_settings.model_dump_json(indent=4).encode())
|
2025-06-12 19:21:58 +02:00
|
|
|
|
|
2025-06-06 20:18:29 +02:00
|
|
|
|
|
2025-06-13 20:23:19 +02:00
|
|
|
|
app_settings = AppSettings()
|
|
|
|
|
|
print(app_settings)
|
|
|
|
|
|
|
2025-06-06 20:18:29 +02:00
|
|
|
|
class PdfProjectSettings(BaseSettings):
|
|
|
|
|
|
"""
|
2025-06-12 19:21:58 +02:00
|
|
|
|
Speichert Projekt-Einstellungen direkt im Ordner des Projekts in einer Klartextdatei JSON
|
2025-06-06 20:18:29 +02:00
|
|
|
|
"""
|
2025-06-06 20:32:23 +02:00
|
|
|
|
|
2025-06-06 20:18:29 +02:00
|
|
|
|
pass
|