From 6282eed349dc56a11e201ccb01d673cb8f021486 Mon Sep 17 00:00:00 2001 From: Midgard Date: Mon, 22 Jun 2020 19:22:47 +0200 Subject: [PATCH] Improve app.py It should always create and expose the app object for uWSGI. --- app/app.py | 33 +++++++++++++-------------------- app/database/create_database.py | 7 +++---- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/app/app.py b/app/app.py index 2d7b63c..9bf0eaa 100755 --- a/app/app.py +++ b/app/app.py @@ -23,26 +23,9 @@ from utils import euro_string, price_range_string from zeus import init_oauth -def create_app() -> Manager: - "Create the Haldis application" - app = Flask(__name__) - - # Load the config file - app.config.from_object("config.Configuration") - - app_manager = register_plugins(app) - add_handlers(app) - add_routes(app) - add_template_filters(app) - - # TODO do we need to return and then run the manager? - return app_manager - - def register_plugins(app: Flask) -> Manager: - "Register all the plugins to Haldis" + "Register Airbrake and logrotation plugins" # pylint: disable=W0612 - # Register Airbrake and enable the logrotation if not app.debug: timedFileHandler = TimedRotatingFileHandler( app.config["LOGFILE"], when="midnight", backupCount=100 @@ -175,7 +158,17 @@ def add_template_filters(app: Flask) -> None: app.template_filter("any")(any) +app = Flask(__name__) + +# Load the config file +app.config.from_object("config.Configuration") + +app_manager = register_plugins(app) +add_handlers(app) +add_routes(app) +add_template_filters(app) + + # For usage when you directly call the script with python if __name__ == "__main__": - manager = create_app() - manager.run() + app_manager.run() diff --git a/app/database/create_database.py b/app/database/create_database.py index b7f4bb1..199c3aa 100644 --- a/app/database/create_database.py +++ b/app/database/create_database.py @@ -1,6 +1,6 @@ "Script for interaction and changes to the database" import add_admins -from app import db, create_app +from app import db, app_manager entry_sets = { "admins": add_admins.add, @@ -69,9 +69,8 @@ def add_to_current() -> None: print("Not a valid answer.") print("Thank you for adding, come again!") -manager = create_app() -@manager.command +@app_manager.command def setup_database(): #type: None "Start the database interaction script" print("Database modification script!") @@ -83,4 +82,4 @@ def setup_database(): #type: None commit() -manager.run() +app_manager.run()