"""Entry point for cPanel "Setup Python App" (Phusion Passenger), which looks for `application` in this file.

On the very first start the database is created and filled with the site content, so the site works
even if nobody runs `python manage.py init-db`. An existing database is never touched.
"""
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from app import create_app  # noqa: E402
from app.db import connect  # noqa: E402
from app.seed import seed  # noqa: E402

application = create_app()

_con = connect(application.config['DATABASE'])
try:
    seed(_con)
finally:
    _con.close()
