Skip to content

Commit

Permalink
Merge pull request #54 from OzNetNerd/fix/53/choose-config-class
Browse files Browse the repository at this point in the history
Select prod or debug class based on environment variable - Issue #53
  • Loading branch information
afourmy committed May 16, 2018
2 parents 6015557 + 6516e8d commit e206190
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions source/flask_app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
from config import DebugConfig
from config import DebugConfig, ProductionConfig
from flask import Flask
from flask_migrate import Migrate
from importlib import import_module
from os import environ
from os.path import abspath, dirname, join, pardir
import sys
import logging

# prevent python from writing *.pyc files / __pycache__ folders
sys.dont_write_bytecode = True

get_config_mode = environ.get('ENMS_CONFIG_MODE', 'Production')
format_config_mode = "".join([get_config_mode.capitalize(), "Config"])

try:
config_mode = getattr(sys.modules[__name__], format_config_mode)
except AttributeError:
sys.exit('Error: Invalid ENMS_CONFIG_MODE environment variable entry.')

path_source = dirname(abspath(__file__))
path_parent = abspath(join(path_source, pardir))
if path_source not in sys.path:
Expand Down Expand Up @@ -99,7 +108,7 @@ def configure_scheduler(scheduler):

def create_app(test=False):
app = Flask(__name__, static_folder='base/static')
app.config.from_object(DebugConfig)
app.config.from_object(config_mode)
initialize_paths(app)
register_extensions(app, test)
register_blueprints(app)
Expand Down

0 comments on commit e206190

Please sign in to comment.