|
@ -1,16 +1,12 @@ |
|
|
""" |
|
|
|
|
|
Atheneum Flask Application |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
"""Atheneum Flask Application.""" |
|
|
import os |
|
|
import os |
|
|
from logging.config import dictConfig |
|
|
from logging.config import dictConfig |
|
|
|
|
|
|
|
|
from flask import Flask |
|
|
from flask import Flask |
|
|
from flask_migrate import Migrate, upgrade |
|
|
|
|
|
from flask_sqlalchemy import SQLAlchemy |
|
|
|
|
|
|
|
|
from flask_migrate import Migrate |
|
|
|
|
|
|
|
|
from atheneum import utility |
|
|
|
|
|
|
|
|
|
|
|
db: SQLAlchemy = SQLAlchemy() |
|
|
|
|
|
|
|
|
from atheneum.db import db |
|
|
|
|
|
from atheneum.utility import json_utility |
|
|
|
|
|
|
|
|
dictConfig({ |
|
|
dictConfig({ |
|
|
'version': 1, |
|
|
'version': 1, |
|
@ -31,69 +27,64 @@ dictConfig({ |
|
|
|
|
|
|
|
|
def create_app(test_config: dict = None) -> Flask: |
|
|
def create_app(test_config: dict = None) -> Flask: |
|
|
""" |
|
|
""" |
|
|
Create an instance of Atheneum |
|
|
|
|
|
|
|
|
Create an instance of Atheneum. |
|
|
|
|
|
|
|
|
:param test_config: |
|
|
:param test_config: |
|
|
:return: |
|
|
:return: |
|
|
""" |
|
|
""" |
|
|
atheneum_app = Flask(__name__, instance_relative_config=True) |
|
|
|
|
|
logger = atheneum_app.logger() |
|
|
|
|
|
logger.debug('Creating Atheneum Server') |
|
|
|
|
|
|
|
|
app = Flask(__name__, instance_relative_config=True) |
|
|
|
|
|
app.logger.debug('Creating Atheneum Server') |
|
|
|
|
|
|
|
|
data_directory = os.getenv('ATHENEUM_DATA_DIRECTORY', '/tmp') |
|
|
data_directory = os.getenv('ATHENEUM_DATA_DIRECTORY', '/tmp') |
|
|
logger.debug('Atheneum Data Directory: %s', data_directory) |
|
|
|
|
|
|
|
|
app.logger.debug('Atheneum Data Directory: %s', data_directory) |
|
|
|
|
|
|
|
|
default_database_uri = 'sqlite:///{}/atheneum.db'.format(data_directory) |
|
|
default_database_uri = 'sqlite:///{}/atheneum.db'.format(data_directory) |
|
|
atheneum_app.config.from_mapping( |
|
|
|
|
|
|
|
|
app.config.from_mapping( |
|
|
SECRET_KEY='dev', |
|
|
SECRET_KEY='dev', |
|
|
SQLALCHEMY_DATABASE_URI=default_database_uri, |
|
|
SQLALCHEMY_DATABASE_URI=default_database_uri, |
|
|
SQLALCHEMY_TRACK_MODIFICATIONS=False |
|
|
SQLALCHEMY_TRACK_MODIFICATIONS=False |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
if test_config is None: |
|
|
if test_config is None: |
|
|
logger.debug('Loading configurations') |
|
|
|
|
|
atheneum_app.config.from_object('atheneum.default_settings') |
|
|
|
|
|
atheneum_app.config.from_pyfile('config.py', silent=True) |
|
|
|
|
|
|
|
|
app.logger.debug('Loading configurations') |
|
|
|
|
|
app.config.from_object('atheneum.default_settings') |
|
|
|
|
|
app.config.from_pyfile('config.py', silent=True) |
|
|
if os.getenv('ATHENEUM_SETTINGS', None): |
|
|
if os.getenv('ATHENEUM_SETTINGS', None): |
|
|
atheneum_app.config.from_envvar('ATHENEUM_SETTINGS') |
|
|
|
|
|
|
|
|
app.config.from_envvar('ATHENEUM_SETTINGS') |
|
|
else: |
|
|
else: |
|
|
logger.debug('Loading test configuration') |
|
|
|
|
|
atheneum_app.config.from_object(test_config) |
|
|
|
|
|
|
|
|
app.logger.debug('Loading test configuration') |
|
|
|
|
|
app.config.from_object(test_config) |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
os.makedirs(atheneum_app.instance_path) |
|
|
|
|
|
|
|
|
os.makedirs(app.instance_path) |
|
|
except OSError: |
|
|
except OSError: |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
|
atheneum_app.json_encoder = utility.CustomJSONEncoder |
|
|
|
|
|
|
|
|
app.json_encoder = json_utility.CustomJSONEncoder |
|
|
|
|
|
|
|
|
logger.debug('Initializing Application') |
|
|
|
|
|
db.init_app(atheneum_app) |
|
|
|
|
|
logger.debug('Registering Database Models') |
|
|
|
|
|
Migrate(atheneum_app, db) |
|
|
|
|
|
|
|
|
app.logger.debug('Initializing Application') |
|
|
|
|
|
db.init_app(app) |
|
|
|
|
|
app.logger.debug('Registering Database Models') |
|
|
|
|
|
Migrate(app, db) |
|
|
|
|
|
|
|
|
return atheneum_app |
|
|
|
|
|
|
|
|
return app |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def register_blueprints(atheneum_app: Flask) -> None: |
|
|
|
|
|
|
|
|
def register_blueprints(app: Flask) -> None: |
|
|
""" |
|
|
""" |
|
|
Register blueprints for the application |
|
|
|
|
|
|
|
|
Register blueprints for the application. |
|
|
|
|
|
|
|
|
:param atheneum_app: |
|
|
|
|
|
|
|
|
:param app: |
|
|
:return: |
|
|
:return: |
|
|
""" |
|
|
""" |
|
|
from atheneum.api import AUTH_BLUEPRINT |
|
|
from atheneum.api import AUTH_BLUEPRINT |
|
|
atheneum_app.register_blueprint(AUTH_BLUEPRINT) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
APP = create_app() |
|
|
|
|
|
register_blueprints(APP) |
|
|
|
|
|
|
|
|
app.register_blueprint(AUTH_BLUEPRINT) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def init_db() -> None: |
|
|
|
|
|
"""Clear existing data and create new tables.""" |
|
|
|
|
|
upgrade('migrations') |
|
|
|
|
|
|
|
|
atheneum = create_app() # pylint: disable=C0103 |
|
|
|
|
|
register_blueprints(atheneum) |
|
|
|
|
|
|
|
|
|
|
|
logger = atheneum.logger # pylint: disable=C0103 |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
APP.run() |
|
|
|
|
|
|
|
|
atheneum.run() |