Varia library working group XPPL. https://gitea.xpub.nl/XPUB/XPPL
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.3 KiB

"""Main application factory."""
from os import makedirs, pardir
from os.path import exists
from flask import Flask
from sqlalchemy.dialects import registry
def create_app(config):
app = Flask(__name__.split('.')[0])
app.config.from_object(config)
configure_pyrqlite()
configure_socketio(app)
configure_sqlalchemy(app)
configure_uploads(app)
with app.app_context():
from xppl import views # noqa
return app
def configure_pyrqlite():
"""Configure PyRQLite."""
registry.register(
'rqlite.pyrqlite',
'sqlalchemy_rqlite.pyrqlite',
'dialect'
)
def configure_sqlalchemy(app):
"""Configure SQLAlchemy."""
from xppl.database import db
from xppl.models import ( # noqa
Book, Author, Instance,
Potential, UserIns, Chat,
Stack,
)
db.init_app(app)
with app.app_context():
db.create_all()
def configure_socketio(app):
"""Configure SocketIO."""
from xppl.socketio import socketio
socketio.init_app(app)
def configure_uploads(app):
"""Setup the uploads folder."""
upload_paths = [
app.config['UPLOAD_FOLDER'],
app.config['UPLOAD_FOLDER_COVER'],
]
for path in upload_paths:
if not exists(path):
makedirs(path)