""" flask apps initialisation """ import logging from logging.handlers import TimedRotatingFileHandler from flask import Flask from pony.flask import Pony from ITPlanning.api import api from ITPlanning.db import init_database from ITPlanning.config import IniConfig from ITPlanning.frontend import frontend logger = logging.getLogger("ITPlanning") def create_app(): """Flask app creation""" app = Flask(__name__, static_folder="static", template_folder="view") config = IniConfig() app.config.from_object(config) # set logger logfile = app.config["LOG"]["log_file"] if logfile: handler = TimedRotatingFileHandler(logfile, when="midnight") handler.setFormatter( logging.Formatter("%(asctime)s [%(levelname)s] %(message)s") ) logger.addHandler(handler) loglevel = app.config["LOG"]["log_level"] if loglevel: logger.setLevel(getattr(logging, loglevel.upper(), logging.NOTSET)) # Initialize database init_database(app.config["BASE"]["database_uri"]) Pony(app) # create flask blueprint app.register_blueprint(api, url_prefix="/api/v1") app.register_blueprint(frontend) return app