import os from config_file import read_config as read_cfg APP_VERSION="1.0.0" SCRIPT_PATH = os.path.dirname(__file__) CONFIGS_DIR = SCRIPT_PATH + "/configs" CONFIG_FILE_NAME = CONFIGS_DIR + "/server_config.yaml" API_KEY = '' UPLOAD_DIR = '.uploads' DB_URL = '' APP_PORT = 25100 IS_DEBUG = False IS_DOCS_AVAILABLE = False def read_app_config(): j, _ = read_cfg(CONFIG_FILE_NAME) return j def get_config_value(cfg, section, key, default): if '.' in section: s = section.split('.', 1) new_section = s[1] new_cfg = cfg[s[0]] return get_config_value(new_cfg, new_section, key, default) else: return cfg[section][key] if section in cfg and key in cfg[section] else default def parse_config(cfg): global UPLOAD_DIR, APP_PORT, IS_DEBUG, DB_URL, IS_DOCS_AVAILABLE UPLOAD_DIR = get_config_value(cfg, 'server', 'directory', UPLOAD_DIR) APP_PORT = get_config_value(cfg, 'server', 'port', APP_PORT) DB_URL = get_config_value(cfg, 'server', 'db_url', DB_URL) IS_DEBUG = get_config_value(cfg, 'server', 'debug', IS_DEBUG) IS_DOCS_AVAILABLE = get_config_value(cfg, 'server', 'docs_available', IS_DOCS_AVAILABLE) def init_config(): config = read_app_config() parse_config(config) if __name__ == '__main__': init_config()