Commit 4f22f3e4 authored by Jonathan Schaeffer's avatar Jonathan Schaeffer

Simplifier le chargement des config

Et toute valeur de RUNMODE peut être prise en compte
parent 0de255b0
# With this code in place, you can call `import configurations` and all .py files in there will be available in the code : configurations.Production.authdb for instance.
import os
import importlib
for module in os.listdir(os.path.dirname(__file__)):
if module == '__init__.py' or module[-3:] != '.py':
continue
importlib.import_module('.'+module[:-3], 'configurations')
del module
......@@ -10,15 +10,19 @@ from flask import Flask, request, Response
import configurations
import psycopg2
from version import __version__
from psycopg2.extensions import AsIs
import importlib
application = Flask(__name__)
if 'RUNMODE' in os.environ and os.environ['RUNMODE'] == 'production':
application.config.from_object(configurations.production.config)
elif 'RUNMODE' in os.environ and os.environ['RUNMODE'] == 'development':
application.config.from_object(configurations.development.config)
if 'RUNMODE' in os.environ:
try:
importlib.import_module('.'+os.environ.get('RUNMODE'), 'configurations')
application.config.from_object('configurations.'+os.environ.get('RUNMODE')+'.config')
except Exception as e:
raise e
# no configuration for this RUNMODE value
else:
application.config.from_object(configurations.default.default)
application.config.from_object('configurations.default.config')
from logging.config import dictConfig
dictConfig({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment