diff --git a/src/wce_crm/__init__.py b/src/wce_crm/__init__.py index f44e039..c6fce6b 100644 --- a/src/wce_crm/__init__.py +++ b/src/wce_crm/__init__.py @@ -1,6 +1,10 @@ import os import sys +import dotenv + if sys.stdout is None or sys.stderr is None: sys.stdout = open(os.devnull, "w") sys.stderr = open(os.devnull, "w") + +dotenv.load_dotenv() diff --git a/src/wce_crm/constants.py b/src/wce_crm/constants.py index e8b1b6d..8df5466 100644 --- a/src/wce_crm/constants.py +++ b/src/wce_crm/constants.py @@ -4,19 +4,11 @@ import os from pathlib import Path from typing import Final -import dotenv from dopt_basics import io as io_ -dotenv.load_dotenv() - # PROJECT_ROOT = Path(__file__).resolve().parents[2] LIB_PATH: Final[Path] = Path(__file__).resolve().parent -# DEV_DB_PATH = PROJECT_ROOT / "data/db" -# DEV_DB_KONTAKTLISTE = DEV_DB_PATH / "wce_kontaktliste.db" -# assert DEV_DB_KONTAKTLISTE.exists() -# DEV_DB_CRM = DEV_DB_PATH / "wce_crm.db" -# assert DEV_DB_CRM.exists() BASE_PATH = io_.search_folder_path( LIB_PATH, stop_folder_name=os.getenv("DOPT_STOP_FOLDER_NAME", "python") @@ -25,10 +17,10 @@ assert BASE_PATH class Config: - DB_PATH_CRM = BASE_PATH / os.getenv("DOPT_DB_CRM", "data/db/wce_crm.db") - DB_PATH_MAIN = BASE_PATH / os.getenv("DOPT_DB_MAIN", "data/db/wce_grunderfassung.db") - - -# def setup(): -# os.environ["DOPT_DB_KONTAKTLISTE"] = str(DEV_DB_KONTAKTLISTE) -# os.environ["DOPT_DB_CRM"] = str(DEV_DB_CRM) + DEVELOPMENT_STATE: bool = bool(os.getenv("DOPT_DEVELOPMENT", "0")) + DB_PATH_CRM: Path = BASE_PATH / os.getenv("DOPT_DB_CRM", "data/db/wce_crm.db") + DB_PATH_MAIN: Path = BASE_PATH / os.getenv( + "DOPT_DB_MAIN", "data/db/wce_grunderfassung.db" + ) + PATH_LOGGING: Path = BASE_PATH / os.getenv("DOPT_PATH_LOGGING", "data/d-opt.log") + LOG_FILENAME: str = "dopt.log" diff --git a/src/wce_crm/logging.py b/src/wce_crm/logging.py new file mode 100644 index 0000000..5f6e855 --- /dev/null +++ b/src/wce_crm/logging.py @@ -0,0 +1,33 @@ +import logging + +from dopt_basics.logging import BASE_LOGGER, setup_logging + +from wce_crm.constants import Config + +enable_stderr: bool = False +enable_file: bool = True + +if Config.DEVELOPMENT_STATE: + enable_stderr = True + enable_file = False + +if not Config.PATH_LOGGING.exists(): + Config.PATH_LOGGING.mkdir() + +setup_logging( + enable_stderr=enable_stderr, + enable_file=enable_file, + logging_dir=Config.PATH_LOGGING, + log_filename=Config.LOG_FILENAME, +) +logger_base = BASE_LOGGER.getChild("wce_crm") + +# ** GUI +logger_gui = logger_base.getChild("gui") +logger_gui.setLevel(logging.DEBUG) +logger_search_widget = logger_gui.getChild("search_widget") +logger_search_widget.setLevel(logging.DEBUG) +logger_get_data = logger_gui.getChild("get_data") +logger_get_data.setLevel(logging.DEBUG) +logger_auto_form = logger_gui.getChild("get_data_auto_form") +logger_auto_form.setLevel(logging.DEBUG)