diff --git a/README.md b/README.md index cb0eefdbe5f142b043a80584751d78893cd9e395..8951be847edd23815dedc44f919a78ab70355c58 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,25 @@ run the application ./run_dev.sh +# Code Guards + +Some python code for management of user accounts within a Flask application. + +## Directories + +Most directories have their own `README.md`. +* `codeguards` : main code, i.e. a blueprint for Flask. +* `docker` : anything for building docker images with all the needed externals. +* `dist` : where we build and store wheel distributions of the main codeguards code. +* `test/instance` : where we initialize a test sqlite database. +* `test/demo_blog` : web demo application. +* `test/scripts` : various command-line test. + +## Demonstration from scratch, with Docker + +With the help of Docker : +1. Build the dev Docker image : `docker/build_externals.sh` +1. Build the codeguards distribution : `docker/run_externals.sh dist/build.sh` +1. Build the demo Docker image : `docker/build_latest.sh` (it includes the above distribution) +1. Initialize a database : `docker/run_latest.sh instance/init_db.sh` +1. Starts the flask server : `docker/run_latest.sh` diff --git a/docker/run_externals.sh b/docker/run_externals.sh index 6eef2a15377a45b4035d65d9bbf275e5a27e9ce1..2c66595f6771207a82c9bbd4cb1e8c363e3f98e4 100755 --- a/docker/run_externals.sh +++ b/docker/run_externals.sh @@ -6,4 +6,4 @@ SCRIPT_NAME=${BASH_SOURCE[0]} cd `dirname ${SCRIPT_NAME}` # Flask opère sur le port 5000 -docker run -it --rm -p 5000:5000 -v $PWD/..:/work -w /work codeguards:dev $* \ No newline at end of file +docker run -it --rm -p 5000:5000 -v $PWD/..:/work -w /work labelstower:dev $* \ No newline at end of file diff --git a/app/labels_system/__init__.py b/labelstower/__init__.py similarity index 63% rename from app/labels_system/__init__.py rename to labelstower/__init__.py index 5c1516ef35be33d5be7ce8c9a60bdf0cea0a5eea..7c8f1f7b7ad85b90aea31266906b34e9c3c5577e 100644 --- a/app/labels_system/__init__.py +++ b/labelstower/__init__.py @@ -2,5 +2,5 @@ from flask import Blueprint bp = Blueprint('sort', __name__) -from app.labels_system import routes +from labelstower import routes diff --git a/app/labels_system/getter.py b/labelstower/getter.py similarity index 100% rename from app/labels_system/getter.py rename to labelstower/getter.py diff --git a/app/labels_system/request_db.py b/labelstower/request_db.py similarity index 93% rename from app/labels_system/request_db.py rename to labelstower/request_db.py index 602c4a87950c8910b294ac283d8b97245b2d78e6..4cc119a770eb264b72f39fe1e2f2496c1a0d63f9 100644 --- a/app/labels_system/request_db.py +++ b/labelstower/request_db.py @@ -1,5 +1,5 @@ from typing import Dict, List -from app import db +from labelstower import db def send_query_to_db(query: str) -> List[Dict[int, str]] : ''' diff --git a/app/labels_system/routes.py b/labelstower/routes.py similarity index 87% rename from app/labels_system/routes.py rename to labelstower/routes.py index 249788514ae55d7e7aaee15be80481c9efafddb0..b2f74963506ce4465c886d7feeca40e5031da4c1 100644 --- a/app/labels_system/routes.py +++ b/labelstower/routes.py @@ -1,7 +1,7 @@ from typing import Dict, List import json -from app.labels_system.getter import get_selected_elements, get_discriminating_labels, get_high_discriminating_labels, get_user_selection -from app.labels_system import bp +from labelstower.getter import get_selected_elements, get_discriminating_labels, get_high_discriminating_labels, get_user_selection +from labelstower import bp #URLs call to update labels and elements along researchs diff --git a/test/demo_flask/__init__.py b/test/demo_flask/__init__.py index 0f4d397e92b8a6a3474d59e2491be89279e2b0c9..0fa71731aa5004c81bbd968d6f9b8f38edfd02aa 100644 --- a/test/demo_flask/__init__.py +++ b/test/demo_flask/__init__.py @@ -25,7 +25,7 @@ def create_app(): app.config.from_object(os.environ['LABELSTOWER_ENV']) - from app.labels_system import bp + from labelstower import bp app.register_blueprint(bp, url_prefix='/sort') @app.route('/') diff --git a/test/instance/init_db.sh b/test/instance/init_db.sh index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0b97342d222a16962d4b284d1afa22612dc75b83 100644 --- a/test/instance/init_db.sh +++ b/test/instance/init_db.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# This ensures that we are in this script directory, +# even if we call it from another one. +SCRIPT_NAME=${BASH_SOURCE[0]} +cd `dirname ${SCRIPT_NAME}` + +rm -f codeguards.sqlite +cd .. # so to see demo_blog +python3 -c 'from demo_flask.models import db; from demo import create_app; db.create_all(app=create_app());' +cd instance +sqlite3 codeguards.sqlite '.read insert_roles.sql' +sqlite3 codeguards.sqlite '.read insert_data.sql' \ No newline at end of file