Files @ e9e85b209c6f
Branch filter:

Location: FVDE/ennstatus/ennstatus/__init__.py

Dennis Fink
Use rt instead of rtkit
# Ënnstatus
# Copyright (C) 2015  Dennis Fink
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os.path
import json

from flask import Flask, render_template
from flask.ext.bootstrap import Bootstrap
from flask.ext.wtf import CsrfProtect
from flask.ext.moment import Moment

from werkzeug.contrib.fixers import ProxyFix

import gnupg

bootstrap = Bootstrap()
csrf = CsrfProtect()
moment = Moment()

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


def create_app():

    app = Flask(__name__)

    import ennstatus.config as config
    config.init_app(app)

    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)

    bootstrap.init_app(app)
    csrf.init_app(app)
    moment.init_app(app)

    from .status.functions import mail
    mail.init_app(app)

    from .root.views import root_page
    app.register_blueprint(root_page)

    from .api.views import api_page
    app.register_blueprint(api_page, url_prefix='/api')

    from .donate.views import donate_page
    app.register_blueprint(donate_page, url_prefix='/donate')

    from .status.views import status_page
    app.register_blueprint(status_page, url_prefix='/status')

    from .statistics.views import statistics_page
    app.register_blueprint(statistics_page, url_prefix='/statistics')

    from .data.views import data_page
    app.register_blueprint(data_page, url_prefix='/data')

    from .log import init_logging
    init_logging(app)

    if 'ENNSTATUS_GPG_HOME' in app.config:
        gpg = gnupg.GPG(gnupghome=app.config['ENNSTATUS_GPG_HOME'])
        gpg.encoding = 'utf-8'
        app.extensions['gnupg'] = gpg
    else:
        app.extensions['gnupg'] = False

    @app.errorhandler(404)
    def page_not_found(e):
        return render_template('errorpages/404.html')

    return app