29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
import yaml
|
|
import os
|
|
|
|
config = {}
|
|
|
|
def parse_bool_env(var_name: str, default: str) -> bool:
|
|
value = str(os.environ.get(var_name, default)).strip().lower()
|
|
return value in ('1', 'true', 'yes', 'on')
|
|
|
|
def load_config(debug: bool = False):
|
|
global config
|
|
|
|
if debug:
|
|
with open('config.yml', 'r') as config_file:
|
|
config = yaml.safe_load(config_file)
|
|
else:
|
|
config = {
|
|
'ttf_host': str(os.environ.get('TTF_HOST', '0.0.0.0')),
|
|
'ttf_port': int(os.environ.get('TTF_PORT', 3424)),
|
|
'ttf_key': str(os.environ.get('TTF_KEY', 'asdf')),
|
|
'ttf_postgres_host': str(os.environ.get('TTF_POSTGRES_HOST')),
|
|
'ttf_postgres_db_name': str(os.environ.get('TTF_POSTGRES_DB_NAME')),
|
|
'ttf_postgres_user': str(os.environ.get('TTF_POSTGRES_USER')),
|
|
'ttf_postgres_password': str(os.environ.get('TTF_POSTGRES_PASSWORD')),
|
|
'ttf_log_file': str(os.environ.get('TTF_LOG_FILE', 'ttf.log')),
|
|
'ttf_print_logs': parse_bool_env('TTF_PRINT_LOGS', 'true'),
|
|
'ttf_write_logs': parse_bool_env('TTF_WRITE_LOGS', 'true'),
|
|
}
|