40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
"""create_app application factory function and similar things."""
|
|
import logging
|
|
import os
|
|
from logging.config import dictConfig
|
|
|
|
from flask import Flask, request
|
|
|
|
from ._version import get_versions
|
|
|
|
__version__ = get_versions()['version']
|
|
del get_versions
|
|
|
|
|
|
def create_app(test_config=None):
|
|
app = Flask(__name__, instance_relative_config=True)
|
|
|
|
# if it doesn't already exist, create the instance folder
|
|
os.makedirs(app.instance_path, exist_ok=True)
|
|
|
|
if test_config is None:
|
|
# load defaults from config provided with the application
|
|
app.config.from_object('incorporealcms.config.Config')
|
|
# load specific instance configurations
|
|
app.config.from_pyfile('config.py', silent=True)
|
|
else:
|
|
app.config.from_mapping(test_config)
|
|
|
|
dictConfig(app.config['LOGGING'])
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
@app.before_request
|
|
def log_request():
|
|
logger.info("REQUEST: [ %s ]", request.path)
|
|
|
|
from . import journal
|
|
app.register_blueprint(journal.bp)
|
|
|
|
return app
|