Skip to content
Snippets Groups Projects
Commit 0a70f891 authored by CHAMONT David's avatar CHAMONT David
Browse files

mise au point de l'intialistion.

parent 2860d530
No related branches found
No related tags found
1 merge request!64Reproduction de la structure mise au point dans CodeGuards
...@@ -15,7 +15,7 @@ RUN pip3 install labelstower-latest-py3-none-any.whl ...@@ -15,7 +15,7 @@ RUN pip3 install labelstower-latest-py3-none-any.whl
# Run flask # Run flask
EXPOSE 80 EXPOSE 5000
ENV FLASK_APP=demo ENV FLASK_APP=demo
ENV FLASK_ENV=production ENV FLASK_ENV=production
......
LAST MINUTE : if you want to run such a container with no command, LAST MINUTE : if you want to run such a container with no command,
that is with the default flask command, then one must define `LT_CFG`` that is with the default flask command, then one must define `LT_CFG``
environment variable before, so that docker defines `LABELSTOWER_ENV=demo.config.Config${LF_CFG}` environment variable before, so that docker defines `LABELSTOWER_ENV=demo.config.Config${LT_CFG}`
for the need of the demo web application. for the need of the demo web application.
# Directory for Docker images and utility scripts # Directory for Docker images and utility scripts
......
#!/usr/bin/env bash
export PYTHONPATH=`pwd`
export LABELSTOWER_ENV="demo.config.Config${LT_CFG}"
flask run --reload --host 0.0.0.0
...@@ -6,4 +6,4 @@ SCRIPT_NAME=${BASH_SOURCE[0]} ...@@ -6,4 +6,4 @@ SCRIPT_NAME=${BASH_SOURCE[0]}
cd `dirname ${SCRIPT_NAME}` cd `dirname ${SCRIPT_NAME}`
# Flask opère sur le port 5000 # Flask opère sur le port 5000
docker run -it --rm -p 5000:5000 -v $PWD/..:/work -w /work --env LF_CFG="${LF_CFG}" labelstower:externals $* docker run -it --rm -p 5000:5000 -v $PWD/..:/work -w /work --env LT_CFG="${LT_CFG}" labelstower:externals $*
...@@ -6,4 +6,4 @@ SCRIPT_NAME=${BASH_SOURCE[0]} ...@@ -6,4 +6,4 @@ SCRIPT_NAME=${BASH_SOURCE[0]}
cd `dirname ${SCRIPT_NAME}` cd `dirname ${SCRIPT_NAME}`
# Flask opère sur le port 5000 # Flask opère sur le port 5000
docker run -it --rm -p 5000:5000 -v $PWD/..:/work -w /work/test --env LF_CFG="${LF_CFG}" labelstower:latest $* docker run -it --rm -p 5000:5000 -v $PWD/../test:/work -w /work --env LT_CFG="${LT_CFG}" labelstower:latest $*
\ No newline at end of file \ No newline at end of file
from typing import Dict, List from typing import Dict, List
from .request_db import send_query_to_db from .request_db import send_query_to_db
from ..labelstower import bp from . import bp
def get_selected_elements(id_mandatory_labels: int, id_forbiden_labels: str, number_of_mandatory_labels: str) -> List[Dict[int, str]] : def get_selected_elements(id_mandatory_labels: int, id_forbiden_labels: str, number_of_mandatory_labels: str) -> List[Dict[int, str]] :
......
from typing import Dict, List from typing import Dict, List
from ..labelstower import bp from . import bp
def send_query_to_db(query: str) -> List[Dict[int, str]] : def send_query_to_db(query: str) -> List[Dict[int, str]] :
''' '''
......
from typing import Dict, List from typing import Dict, List
import json import json
from ..labelstower.getter import get_selected_elements, get_discriminating_labels, get_high_discriminating_labels, get_user_selection from .getter import get_selected_elements, get_discriminating_labels, get_high_discriminating_labels, get_user_selection
from ..labelstower import bp from . import bp
#URLs call to update labels and elements along researchs #URLs call to update labels and elements along researchs
......
...@@ -20,9 +20,8 @@ def create_app(): ...@@ -20,9 +20,8 @@ def create_app():
} }
app = CustomFlask(__name__) app = CustomFlask(__name__)
CORS(app) CORS(app)
db.init_app(app)
app.config.from_object(os.environ['LABELSTOWER_ENV']) app.config.from_object(os.environ['LABELSTOWER_ENV'])
db.init_app(app)
from labelstower import bp as bp_labels from labelstower import bp as bp_labels
bp_labels.db = db bp_labels.db = db
......
class ConfigCodingPool(): class ConfigCodingPool():
SQLALCHEMY_DATABASE_URI = 'sqlite:///../instance/CodingPool.sqlite' SQLALCHEMY_DATABASE_URI = 'sqlite:///../instance/CodingPool.sqlite'
SQLALCHEMY_TRACK_MODIFICATIONS = False
class ConfigVoiture(): class ConfigVoiture():
SQLALCHEMY_DATABASE_URI = 'sqlite:///../instance/Voiture.sqlite' SQLALCHEMY_DATABASE_URI = 'sqlite:///../instance/Voiture.sqlite'
\ No newline at end of file SQLALCHEMY_TRACK_MODIFICATIONS = False
from flask import Flask from flask import Flask
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
import os from . import db
app = Flask(__name__)
app.config.from_object(os.environ['LABELSTOWER_ENV'])
db = SQLAlchemy(app)
element_label = db.Table('Element_Label', db.Model.metadata, element_label = db.Table('Element_Label', db.Model.metadata,
db.Column('id_element', db.Integer, db.ForeignKey('element.id')), db.Column('id_element', db.Integer, db.ForeignKey('element.id')),
......
# Directory for the test database instanciation
This is the directory where we can create a database for the tests.
## Requirements
We use SQLite for the tests.
If one wants also to take profit of the utility scripts provided in the current directory, the command `/usr/bin/env bash` (used as a shebang in the scripts) must return a valid bash shell.
## Scripts
The script `init_db.sh` requires a python3 environment where the wheel from the `../../dist` directory has been already installed with `pip3`.
If the wheel is not already installed, rather use `pip_init_db.sh`. This is typically useful if you create your database with a docker command.
...@@ -5,8 +5,11 @@ ...@@ -5,8 +5,11 @@
SCRIPT_NAME=${BASH_SOURCE[0]} SCRIPT_NAME=${BASH_SOURCE[0]}
cd `dirname ${SCRIPT_NAME}` cd `dirname ${SCRIPT_NAME}`
export LABELSTOWER_ENV="demo.config.Config${LT_CFG}"
echo LABELSTOWER_ENV "demo.config.Config${LT_CFG}"
rm -f ${LT_CFG}.sqlite rm -f ${LT_CFG}.sqlite
cd .. # so to see demo_blog cd .. # so to see demo_blog
python3 -c 'from demo.models import db; from demo import create_app; db.create_all(app=create_app());' python3 -c 'from demo.models import db; from demo import create_app; db.create_all(app=create_app());'
cd instance cd instance
sqlite3 ${LT_CFG}.sqlite '.read Data${LT_CFG}.sql' sqlite3 ${LT_CFG}.sqlite ".read Data${LT_CFG}.sql"
...@@ -5,5 +5,7 @@ ...@@ -5,5 +5,7 @@
SCRIPT_NAME=${BASH_SOURCE[0]} SCRIPT_NAME=${BASH_SOURCE[0]}
cd `dirname ${SCRIPT_NAME}` cd `dirname ${SCRIPT_NAME}`
export LABELSTOWER_ENV="demo.config.Config${LT_CFG}"
cd ../.. cd ../..
python3 labelstower/getter.py python3 labelstower/getter.py
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment