Provisions-Manager 95: Import, Händler-DB, Auszahlungsregeln, Excel-Export, Win95-Oberfläche, Wine-Build
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
322d2ed1c3
25 files changed
+3366
No files matched your search
@@ -0,0 +1,61 @@
|
||||
"""Speicherorte und Einstellungen.
|
||||
|
||||
Die Einstellungen liegen als JSON in %APPDATA%\\Provisionsmanager95\\einstellungen.json.
|
||||
Darin steht u. a. der Pfad zur Datenbank – der kann bewusst auf ein Netzlaufwerk
|
||||
zeigen, wenn mehrere PCs (nacheinander) mit denselben Händlerdaten arbeiten sollen.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
APP_DIR_NAME = "Provisionsmanager95"
|
||||
|
||||
|
||||
def app_dir() -> Path:
|
||||
base = os.environ.get("PROVTOOL_HOME")
|
||||
if base:
|
||||
p = Path(base)
|
||||
elif os.name == "nt" and os.environ.get("APPDATA"):
|
||||
p = Path(os.environ["APPDATA"]) / APP_DIR_NAME
|
||||
else:
|
||||
p = Path.home() / ".config" / APP_DIR_NAME
|
||||
p.mkdir(parents=True, exist_ok=True)
|
||||
return p
|
||||
|
||||
|
||||
def _settings_file() -> Path:
|
||||
return app_dir() / "einstellungen.json"
|
||||
|
||||
|
||||
DEFAULTS = {
|
||||
"db_pfad": None, # None = Standard im App-Verzeichnis
|
||||
"export_ordner": None,
|
||||
"import_ordner": None,
|
||||
"export_kopfzeile": False,
|
||||
"export_summe": True,
|
||||
"export_pro_anbieter": True,
|
||||
}
|
||||
|
||||
|
||||
def load() -> dict:
|
||||
data = dict(DEFAULTS)
|
||||
f = _settings_file()
|
||||
if f.exists():
|
||||
try:
|
||||
data.update(json.loads(f.read_text(encoding="utf-8")))
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
return data
|
||||
|
||||
|
||||
def save(data: dict) -> None:
|
||||
_settings_file().write_text(json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
|
||||
|
||||
def db_path(settings: dict | None = None) -> Path:
|
||||
settings = settings or load()
|
||||
if settings.get("db_pfad"):
|
||||
return Path(settings["db_pfad"])
|
||||
return app_dir() / "provisionen.db"
|
||||
Reference in new issue
Block a user