Module psdi_data_conversion.gui.setup

setup.py

This module handles setting up the Flask app

Functions

def get_app() ‑> flask.app.Flask
Expand source code
def get_app() -> Flask:
    """Get a reference to the global `Flask` app, creating it if necessary.
    """
    global _app
    if not _app:
        _app = _init_app()
    return _app

Get a reference to the global Flask app, creating it if necessary.

def limit_upload_size(app: flask.app.Flask | None = None)
Expand source code
def limit_upload_size(app: Flask | None = None):
    """Impose a limit on the maximum file that can be uploaded before Flask will raise an error"""

    if app is None:
        app = get_app()

    env = get_env()

    # Determine the largest possible file size that can be uploaded, keeping in mind that 0 indicates unlimited
    larger_max_file_size = env.max_file_size
    if (env.max_file_size > 0) and (env.max_file_size_ob > env.max_file_size):
        larger_max_file_size = env.max_file_size_ob

    if larger_max_file_size > 0:
        app.config['MAX_CONTENT_LENGTH'] = larger_max_file_size
    else:
        app.config['MAX_CONTENT_LENGTH'] = None

Impose a limit on the maximum file that can be uploaded before Flask will raise an error

def start_app()
Expand source code
def start_app():
    """Start the Flask app - this requires being run from the base directory of the project, so this changes the
    current directory to there. Anything else which changes it while the app is running may interfere with its proper
    execution.
    """

    old_cwd = os.getcwd()

    try:
        os.chdir(os.path.join(psdi_data_conversion.__path__[0], ".."))
        get_app().run(debug=get_env().debug_mode)
    finally:
        # Return to the previous directory after running the app
        os.chdir(old_cwd)

Start the Flask app - this requires being run from the base directory of the project, so this changes the current directory to there. Anything else which changes it while the app is running may interfere with its proper execution.