Example #1
0
File: app.py Project: mianos/etemp
def create_app():
    app = Flask(__name__)
    app.secret_key = "sdjadsldjasklj"

    app.settings = configobj.ConfigObj("settings.ini")

    engine = create_engine(app.settings["database"]["connection"])
    Session = sessionmaker(bind=engine)  # autocommit=True)

    menu.init_app(app)
    jinja_local.jinja_filters.init_app(app)
    app.register_blueprint(reports.reports, url_prefix="/reports")
    app.register_blueprint(graphs.graphs, url_prefix="/graphs")
    app.register_blueprint(receiver.receiver)
    app.register_blueprint(auth)

    @app.route("/")
    def root():
        return redirect(url_for("reports.values"))

    @app.after_request
    def session_commit(response):
        session = getattr(g, "session", None)
        if session is not None:
            g.session.commit()
        return response

    @app.before_request
    def before_request():
        g.session = Session()

    @app.teardown_request
    def teardown_request(exception):
        session = getattr(g, "session", None)
        if session is not None:
            session.close()

    return app
Example #2
0
if os.path.exists(file_path):
    # Check secret key file permissions
    mode = os.stat(file_path).st_mode

    if mode & stat.S_IRWXU != 384 or mode & stat.S_IRWXG != 0 or mode & stat.S_IRWXO != 0:
        raise Exception("%s file permissions should be 600\n" % file_path)

    parser = ConfigParser.ConfigParser()
    parser.read([file_path])

    # Set application secret key
    app.secret_key = parser.get("main", "secret_key")
    parser.remove_option("main", "secret_key")

    # Set application settings parser
    app.settings = parser

# Register modules
app.register_blueprint(jira)
app.register_blueprint(nagios)
app.register_blueprint(rman)
app.register_blueprint(sqlrelay)


@app.before_request
def before_request():
    g.cache = FileSystemCache(os.path.join(DATA_DIR, "cache"))


@app.teardown_request
def teardown_request(e):