config.json wird automatisch angelegt.
This commit is contained in:
+37
-7
@@ -1,7 +1,23 @@
|
|||||||
|
from os import path
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from sys import platform
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from pydantic_settings import BaseSettings # , SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
|
app_name = "DocuMentor"
|
||||||
|
|
||||||
|
|
||||||
|
if platform == "win32":
|
||||||
|
config_path = f"%APPDATA%\\{app_name}\\config.json"
|
||||||
|
elif platform == "linux" or platform == "linux2":
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
||||||
class JavaVm(BaseModel):
|
class JavaVm(BaseModel):
|
||||||
@@ -51,17 +67,31 @@ class PdfProject(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class AppSettings(BaseSettings):
|
class AppSettings(BaseSettings):
|
||||||
java_vms: list[JavaVm]
|
java_vms: list[JavaVm] = []
|
||||||
diff_pdfs: list[DiffPdf]
|
diff_pdfs: list[DiffPdf] = []
|
||||||
saxon_jars: list[SaxonJar]
|
saxon_jars: list[SaxonJar] = []
|
||||||
apache_fops: list[ApacheFop]
|
apache_fops: list[ApacheFop] = []
|
||||||
xsl_dirs: list[XslDir]
|
xsl_dirs: list[XslDir] = []
|
||||||
pdf_projects: list[PdfProject] = []
|
pdf_projects: list[PdfProject] = []
|
||||||
|
|
||||||
|
model_config = SettingsConfigDict(json_file=config_path)
|
||||||
|
|
||||||
|
app_settings = AppSettings()
|
||||||
|
|
||||||
|
if not config_path.exists():
|
||||||
|
# Datei existert nicht
|
||||||
|
if not config_path.parent.exists():
|
||||||
|
# Ordner existiert nicht
|
||||||
|
config_path.parent.mkdir()
|
||||||
|
|
||||||
|
# Konfiguration speichern
|
||||||
|
with open(config_path, "wb") as c:
|
||||||
|
c.write(app_settings.model_dump_json(indent=4).encode())
|
||||||
|
|
||||||
|
|
||||||
class PdfProjectSettings(BaseSettings):
|
class PdfProjectSettings(BaseSettings):
|
||||||
"""
|
"""
|
||||||
Speichert Projekt-Einstellungen direkt im Ordner des Projekts in einer Klartextdatei (JSON, YAML oder XML)
|
Speichert Projekt-Einstellungen direkt im Ordner des Projekts in einer Klartextdatei JSON
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user