From 7b3dc9d36de1db28a6f36b03de85cf7f527231cc Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 20 Apr 2022 13:44:26 +0300 Subject: Add scaffolding for web app Add a basic scaffolding for the web interface to the quality-control application. --- etc/default_config.py | 9 +++++++++ manifest.scm | 1 + qc_app/__init__.py | 21 +++++++++++++++++++++ qc_app/entry.py | 9 +++++++++ qc_app/parse_error.py | 9 +++++++++ qc_app/parse_success.py | 9 +++++++++ wsgi.py | 20 ++++++++++++++++++++ 7 files changed, 78 insertions(+) create mode 100644 etc/default_config.py create mode 100644 qc_app/__init__.py create mode 100644 qc_app/entry.py create mode 100644 qc_app/parse_error.py create mode 100644 qc_app/parse_success.py create mode 100644 wsgi.py diff --git a/etc/default_config.py b/etc/default_config.py new file mode 100644 index 0000000..80f9d59 --- /dev/null +++ b/etc/default_config.py @@ -0,0 +1,9 @@ +""" +The default configuration file. The values here should be overridden in the +actual configuration file used for the production and staging systems. +""" + +import os + +LOG_LEVEL = os.getenv("LOG_LEVEL", "WARNING") +SECRET_KEY = b"" diff --git a/manifest.scm b/manifest.scm index c41be35..d5ce588 100644 --- a/manifest.scm +++ b/manifest.scm @@ -1,6 +1,7 @@ (specifications->manifest (list "python" "python-mypy" + "python-flask" "python-pylint" "python-pytest" "python-hypothesis")) diff --git a/qc_app/__init__.py b/qc_app/__init__.py new file mode 100644 index 0000000..2dd5758 --- /dev/null +++ b/qc_app/__init__.py @@ -0,0 +1,21 @@ +"""The Quality-Control Web Application entry point""" + +import os +from flask import Flask + +from .entry import entrybp +from .parse_error import parseerrbp +from .parse_success import parsesuccessbp + +def create_app(instance_path): + """The application factory""" + app = Flask( + __name__, instance_path=instance_path, instance_relative_config=True) + app.config.from_pyfile(os.path.join(os.getcwd(), "etc/default_config.py")) + app.config.from_pyfile("config.py") # Override defaults with instance path + + # setup blueprints + app.register_blueprint(entrybp, url_prefix="/") + app.register_blueprint(parseerrbp, url_prefix="/error") + app.register_blueprint(parsesuccessbp, url_prefix="/success") + return app diff --git a/qc_app/entry.py b/qc_app/entry.py new file mode 100644 index 0000000..4963246 --- /dev/null +++ b/qc_app/entry.py @@ -0,0 +1,9 @@ +"""Entry-point module""" +from flask import Blueprint + +entrybp = Blueprint("entry", __name__) + +@entrybp.route("/", methods=["GET", "POST"]) +def upload_file(): + """Enables uploading the files""" + return "STUB: We upload the files here" diff --git a/qc_app/parse_error.py b/qc_app/parse_error.py new file mode 100644 index 0000000..1414b78 --- /dev/null +++ b/qc_app/parse_error.py @@ -0,0 +1,9 @@ +"""Parse Error handling blue print""" +from flask import Blueprint + +parseerrbp = Blueprint("parse_error", __name__) + +@parseerrbp.route("/", methods=["GET"]) +def parse_success(): + """Indicates success if parsing the file is fails""" + return "STUB: Parse error!!!" diff --git a/qc_app/parse_success.py b/qc_app/parse_success.py new file mode 100644 index 0000000..53b9c42 --- /dev/null +++ b/qc_app/parse_success.py @@ -0,0 +1,9 @@ +"""Successful file parsing module""" +from flask import Blueprint + +parsesuccessbp = Blueprint("parse_success", __name__) + +@parsesuccessbp.route("/", methods=["GET"]) +def parse_success(): + """Indicates success if parsing the file is successful""" + return "STUB: Parse success!!!" diff --git a/wsgi.py b/wsgi.py new file mode 100644 index 0000000..be8207d --- /dev/null +++ b/wsgi.py @@ -0,0 +1,20 @@ +"""Run the application""" + +import os + +from qc_app import create_app + +def instance_path(): + """Retrieve the `instance_path`. Raise an exception if not defined.""" + path = os.getenv("QCAPP_INSTANCE_PATH", None) + if path is None: + raise Exception(( + "Configuration Error: Set the `QCAPP_INSTANCE_PATH` environment " + "variable.")) + + return path + +app = create_app(instance_path()) + +if __name__ == "__main__": + app.run() -- cgit v1.2.3