diff options
| author | 0livd <0livd@users.noreply.github.com> | 2017-04-23 17:32:37 +0100 |
|---|---|---|
| committer | Alexis Metaireau <alexis@notmyidea.org> | 2017-04-23 18:32:37 +0200 |
| commit | e3da3b3b7f18fe80f3ecfaa278859db7a9bfdc45 (patch) | |
| tree | 4e43ef013b0800cebbb164cddd5c9bcafe33edb1 /budget/run.py | |
| parent | fb84135fe5892f4321977a48abacf233d3ee0d9c (diff) | |
| download | ihatemoney-mirror-e3da3b3b7f18fe80f3ecfaa278859db7a9bfdc45.zip ihatemoney-mirror-e3da3b3b7f18fe80f3ecfaa278859db7a9bfdc45.tar.gz ihatemoney-mirror-e3da3b3b7f18fe80f3ecfaa278859db7a9bfdc45.tar.bz2 | |
Externalize the settings (#193)
Default settings from app's root path are loaded first
Settings are then overriden by /etc/ihatemoney/ihatemoney.cfg
or by another file which path is set in an env var
Fixes #187
Diffstat (limited to 'budget/run.py')
| -rw-r--r-- | budget/run.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/budget/run.py b/budget/run.py index 3ab036b..00d4326 100644 --- a/budget/run.py +++ b/budget/run.py @@ -12,7 +12,7 @@ from api import api from utils import PrefixedWSGI from utils import minimal_round -app = Flask(__name__) +app = Flask(__name__, instance_path='/etc/ihatemoney', instance_relative_config=True) def pre_alembic_db(): @@ -27,8 +27,18 @@ def pre_alembic_db(): def configure(): """ A way to (re)configure the app, specially reset the settings """ - config_obj = os.environ.get('FLASK_SETTINGS_MODULE', 'merged_settings') - app.config.from_object(config_obj) + default_config_file = os.path.join(app.root_path, 'default_settings.py') + config_file = os.environ.get('IHATEMONEY_SETTINGS_FILE_PATH') + + # Load default settings first + # Then load the settings from the path set in IHATEMONEY_SETTINGS_FILE_PATH var + # If not set, default to /etc/ihatemoney/ihatemoney.cfg + # If the latter doesn't exist no error is raised and the default settings are used + app.config.from_pyfile(default_config_file) + if config_file: + app.config.from_pyfile(config_file) + else: + app.config.from_pyfile('ihatemoney.cfg', silent=True) app.wsgi_app = PrefixedWSGI(app) # Deprecations |
