kissconfig/kissconfig/__init__.py
2024-02-13 19:42:17 +03:00

22 lines
834 B
Python

import os
import shutil
import logging
import sys
from typing import Type
from kissconfig.config import ConfigClass
from kissconfig.loader import Loader, YamlLoader
def load_config(main_config: Type[ConfigClass], loader: Loader = YamlLoader()):
if not os.path.exists(config_path):
logging.warning(f"Unable to locate app config ({config_path})!")
if not os.path.exists(example_config_path):
logging.critical(f"Unable to locate example config ({example_config_path})")
sys.exit(1)
else:
shutil.copy2(example_config_path, config_path)
logging.warning(f"Actual app config (%s) created from example (%s), don't forget to update it!",
config_path, example_config_path)
return main_config.from_file(config_path, config_namespace)