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.
72 lines
1.4 KiB
72 lines
1.4 KiB
"""Main application factory."""
|
|
|
|
from os import makedirs
|
|
from os.path import exists
|
|
|
|
from dotenv import find_dotenv, load_dotenv
|
|
from flask import Flask
|
|
from sqlalchemy.dialects import registry
|
|
|
|
|
|
def create_app(config):
|
|
app = Flask(__name__.split('.')[0])
|
|
|
|
app.config.from_object(config)
|
|
|
|
configure_dotenv()
|
|
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_dotenv():
|
|
"""Configure the environment."""
|
|
load_dotenv(find_dotenv())
|
|
|
|
|
|
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)
|
|
|