""" 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.frontend import frontend from ITPlanning.db import init_database from ITPlanning.config import IniConfig 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 logger.warning(app.config["BASE"]["database_uri"]) init_database(app.config["BASE"]["database_uri"]) Pony(app) return app