Changeset - 699733d29621
[Not reviewed]
version_5
0 1 0
Dennis Fink - 10 years ago 2015-07-21 19:09:54
dennis.fink@c3l.lu
Config file is now a json file
1 file changed with 23 insertions and 2 deletions:
0 comments (0 inline, 0 general)
ennstatus/__init__.py
Show inline comments
 
import os.path
 
import json
 

	
 

	
 
from flask import Flask, render_template
 
from flask.ext.bootstrap import Bootstrap
 
@@ -11,13 +13,32 @@ import gnupg
 
bootstrap = Bootstrap()
 
compress = Compress()
 

	
 
config_file = os.path.abspath('config.json')
 

	
 

	
 
def create_app():
 

	
 
    app = Flask(__name__)
 

	
 
    config_file = os.path.abspath('config.py')
 
    app.config.from_pyfile(config_file)
 
    if not hasattr(app.config, 'from_json'):
 
        def from_json(file, silent=True):
 
            try:
 
                with open(file, encoding='utf-8') as json_file:
 
                    obj = json.load(json_file)
 
            except IOError:
 
                if silent:
 
                    return False
 
                raise
 

	
 
            for key in obj:
 
                if key.isupper():
 
                    app.config[key] = obj[key]
 

	
 
            return True
 

	
 
        app.config.from_json = from_json
 

	
 
    app.config.from_json(config_file)
 

	
 
    app.wsgi_app = ProxyFix(app.wsgi_app)
 

	
0 comments (0 inline, 0 general)