generated from dopt-python/py311
add user-specified config
This commit is contained in:
6
config/wattana.toml
Normal file
6
config/wattana.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[Datenbank]
|
||||
NUTZER = "WATTANA"
|
||||
PASSWORT = "MyWattanaPassword123"
|
||||
HOST = "localhost"
|
||||
PORT = 1521
|
||||
SERVICE_NAME = "FREEPDB1"
|
||||
@@ -1,3 +1,4 @@
|
||||
DOPT_STOP_FOLDER_NAME=python
|
||||
DOPT_INTERNAL_DB=data/wattana.db
|
||||
DOPT_PATH_LOGGING=data/logs
|
||||
DOPT_PATH_CONFIG=config/wattana.toml
|
||||
@@ -4,3 +4,4 @@
|
||||
- DOPT_STOP_FOLDER_NAME: stop folder to find base path
|
||||
- DOPT_INTERNAL_DB: path to internal database where results for further processing are saved, relative to base path
|
||||
- DOPT_PATH_LOGGING: path to logging folder, relative to base path
|
||||
- DOPT_PATH_CONFIG: path to the config file which can be changed by the user/customer
|
||||
|
||||
@@ -4,8 +4,11 @@ import os
|
||||
from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
from dopt_basics import configs
|
||||
from dopt_basics import io as io_
|
||||
|
||||
from wattanalyse import types as t
|
||||
|
||||
# PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
||||
LIB_PATH: Final[Path] = Path(__file__).resolve().parent
|
||||
|
||||
@@ -21,3 +24,10 @@ class Config:
|
||||
DB_PATH_INTERNAL: Path = BASE_PATH / os.getenv("DOPT_INTERNAL_DB", "not_existing")
|
||||
PATH_LOGGING: Path = BASE_PATH / os.getenv("DOPT_PATH_LOGGING", "data/d-opt.log")
|
||||
LOG_FILENAME: str = "dopt.log"
|
||||
PTH_USER_CFG: Path = BASE_PATH / os.getenv("DOPT_PATH_CONFIG", "config/wattana.toml")
|
||||
|
||||
|
||||
user_cfg = configs.load_toml(Config.PTH_USER_CFG)
|
||||
USER_CFG: t.UserConfig = t.UserConfig(
|
||||
Datenbank=t.UserConfig_Datenbank(**user_cfg["Datenbank"])
|
||||
)
|
||||
|
||||
17
src/wattanalyse/types.py
Normal file
17
src/wattanalyse/types.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses as dc
|
||||
|
||||
|
||||
@dc.dataclass(kw_only=True, slots=True)
|
||||
class UserConfig_Datenbank:
|
||||
NUTZER: str
|
||||
PASSWORT: str
|
||||
HOST: str
|
||||
PORT: int
|
||||
SERVICE_NAME: str
|
||||
|
||||
|
||||
@dc.dataclass(kw_only=True, slots=True)
|
||||
class UserConfig:
|
||||
Datenbank: UserConfig_Datenbank
|
||||
Reference in New Issue
Block a user