예제 #1
0
파일: __init__.py 프로젝트: seekely/quagen
def create_app():
    """
    Create and configure an instance of the Flask application.

    Returns:
        (Flask) Flask application object
    """

    # init quagen config
    config.init()

    app = Flask(__name__, instance_relative_config=True, static_url_path="")
    app.config.from_mapping(SECRET_KEY=config.SETTING_APP_SECRET)

    # register the database commands
    app.teardown_appcontext(db.close)
    db.set_context(g)

    # apply the blueprints to the app
    app.register_blueprint(api.API, url_prefix="/api/v1")
    app.register_blueprint(web.WEB)

    # make url_for('index') == url_for('web.index')
    app.add_url_rule("/", endpoint="index")

    return app
예제 #2
0
파일: worker.py 프로젝트: yiwensong/quagen
def main():
    """
    Main
    """
    config.init()

    worker = Worker()
    worker.run()
예제 #3
0
def main():
    """
    Main
    """
    logging.info("Migrator starting up")
    config.init()

    # Retries connection to database until we succeed which allows the
    # migrator to come up before the database
    db.get_connection(True)

    # Run database migrations
    migrate()
예제 #4
0
def main():
    """
    Main
    """
    logging.info("Worker coming online")
    config.init()

    # Wait for the db to be in good state until we fire up
    db.get_connection(True)
    migrator.wait_until_migrated()

    logging.info("Worker now running")
    worker = Worker()
    worker.run()
예제 #5
0
def close(error=None):
    """
    Closes any existing database connection
    """
    global context
    conn = context.pop("db", None)

    if conn is not None:
        conn.close()

    if error:
        pass


def create():
    """
    If no database exists, import a fresh copy of the schema.
    """

    if not os.path.exists(config.PATH_DB_FILE):
        conn = get_connection()
        with open(config.PATH_DB_SCHEMA, mode="r", encoding="utf-8") as f:
            script = f.read()
            conn.executescript(script)


if __name__ == "__main__":
    config.init()
    create()
    print("Initialized the database.")