In progress: Fix configuration logic

This commit is contained in:
Marcus Lindvall 2019-04-08 11:02:14 +02:00
parent 0fae8725e0
commit 9b7d7db996

View file

@ -3,7 +3,7 @@ import os
import yaml import yaml
defaults = { config = {
'alembic': { 'alembic': {
'script_location': 'migrations', 'script_location': 'migrations',
'sqlalchemy.url': ''}, 'sqlalchemy.url': ''},
@ -37,16 +37,6 @@ defaults = {
'version': 1}, 'version': 1},
'sync_interval': 60} 'sync_interval': 60}
try:
with open("config.yml", 'r') as ymlfile:
file_config = yaml.load(ymlfile, Loader=yaml.FullLoader)
config = {**defaults, **file_config} # Syntax introduced in Python 3.5
except IOError as e:
pass
dictConfig(config['logging'])
config['debug'] = os.getenv('ENVIRONEMENT') == 'DEV' config['debug'] = os.getenv('ENVIRONEMENT') == 'DEV'
DB_CONTAINER = os.getenv('APPLICATION_DB_CONTAINER', 'db') DB_CONTAINER = os.getenv('APPLICATION_DB_CONTAINER', 'db')
@ -64,7 +54,17 @@ config['databases']['meta'] = {
'port': os.getenv('META_MYSQL_PORT', 3306), 'port': os.getenv('META_MYSQL_PORT', 3306),
'db': os.getenv('META_MYSQL_DB', 'pyjeeves'), 'db': os.getenv('META_MYSQL_DB', 'pyjeeves'),
} }
# DB_URI = 'postgresql://%(user)s:%(pw)s@%(host)s:%(port)s/%(db)s' % POSTGRES # DB_URI = 'postgresql://%(user)s:%(pw)s@%(host)s:%(port)s/%(db)s' % POSTGRES
config['alembic']['sqlalchemy.url'] = ( config['alembic']['sqlalchemy.url'] = (
'mysql+pymysql://%(user)s:%(pw)s@%(host)s:%(port)s/%(db)s?charset=utf8mb4' % 'mysql+pymysql://%(user)s:%(pw)s@%(host)s:%(port)s/%(db)s?charset=utf8mb4' %
config['databases']['meta']) config['databases']['meta'])
try:
with open("config.yml", 'r') as ymlfile:
file_config = yaml.load(ymlfile, Loader=yaml.FullLoader)
config = {**config, **file_config} # Syntax introduced in Python 3.5
except IOError as e:
pass
dictConfig(config['logging'])