Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@
ORIGINS = app.config.get("ORIGINS")
SSL = app.config.get("SSL")


def get_db_path_from_config():
database_uri = app.config.get("SQLALCHEMY_DATABASE_URI", "")
if database_uri.startswith("sqlite:///"):
return database_uri.replace("sqlite:///", "")
return None


db_path = get_db_path_from_config()
if db_path:
db_dir = os.path.dirname(db_path)
if db_dir and not os.path.exists(db_dir):
os.makedirs(db_dir, exist_ok=True)
init_database(db_path)
print(f"Database initialized at: {db_path}")

flask_cors.CORS(app, origins=ORIGINS)
app.register_blueprint(
blueprint_routes.routes,
Expand Down Expand Up @@ -58,6 +74,6 @@ def return_error():

# ''' Main '''
if __name__ == "__main__":
init_database(app)
print(f"Python is running in {FLASK_DEBUG} mode")
data_folder = app.config.get("DATA_FOLDER_PATH")
upload_folder = app.config.get("UPLOAD_FOLDER")
app.run(debug=FLASK_DEBUG, host=DEFAULT_HOST, port=PORT, ssl_context=SSL)
3 changes: 1 addition & 2 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ geode-common==33.11.0
geode-viewables==3.3.0
Flask[async]==3.0.3
Flask-Cors==6.0.1
werkzeug==3.0.3
Flask-SQLAlchemy==3.1.1
werkzeug==3.0.3
42 changes: 5 additions & 37 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,34 @@
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --output-file=./requirements.txt --pre ./requirements-internal.in ./requirements.in
# pip-compile --output-file=./requirements.txt --pre ./requirements.in
#
asgiref~=3.0
# via flask
blinker~=1.0
# via
# flask
# opengeodeweb-microservice
# via flask
click~=8.0
# via
# flask
# opengeodeweb-microservice
fastjsonschema~=2.0
# via opengeodeweb-microservice
# via flask
flask[async]~=3.0
# via
# -r requirements.in
# flask
# flask-cors
# flask-sqlalchemy
# opengeodeweb-microservice
flask-cors~=6.0
# via -r requirements.in
flask-sqlalchemy~=3.0
# via
# -r requirements.in
# opengeodeweb-microservice
geode-common==33.11.0
# via
# -r requirements.in
# geode-viewables
geode-viewables==3.3.0
# via -r requirements.in
greenlet~=3.0
# via
# opengeodeweb-microservice
# sqlalchemy
itsdangerous~=2.0
# via
# flask
# opengeodeweb-microservice
# via flask
jinja2~=3.0
# via
# flask
# opengeodeweb-microservice
# via flask
markupsafe~=3.0
# via
# jinja2
# opengeodeweb-microservice
# werkzeug
opengeode-core==15.27.4
# via
Expand All @@ -75,19 +54,8 @@ opengeode-io==7.4.0
# -r requirements.in
# geode-viewables
# opengeode-geosciencesio
opengeodeweb-microservice~=1.0
# via -r requirements-internal.in
sqlalchemy~=2.0
# via
# flask-sqlalchemy
# opengeodeweb-microservice
typing-extensions~=4.0
# via
# opengeodeweb-microservice
# sqlalchemy
werkzeug==3.0.3
# via
# -r requirements.in
# flask
# flask-cors
# opengeodeweb-microservice
11 changes: 1 addition & 10 deletions src/opengeodeweb_back/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

# Third party imports
# Local application imports
from opengeodeweb_microservice.database.connection import get_database

DATABASE_FILENAME = "project.db"


class Config(object):
Expand All @@ -18,7 +15,7 @@ class Config(object):
REQUEST_COUNTER = 0
LAST_REQUEST_TIME = time.time()
LAST_PING_TIME = time.time()
SQLALCHEMY_TRACK_MODIFICATIONS = False
DATABASE_FILENAME = "project.db"


class ProdConfig(Config):
Expand All @@ -27,9 +24,6 @@ class ProdConfig(Config):
MINUTES_BEFORE_TIMEOUT = "1"
SECONDS_BETWEEN_SHUTDOWNS = "10"
DATA_FOLDER_PATH = "/data"
SQLALCHEMY_DATABASE_URI = f"sqlite:///{os.path.abspath(
os.path.join(DATA_FOLDER_PATH, DATABASE_FILENAME)
)}"


class DevConfig(Config):
Expand All @@ -39,6 +33,3 @@ class DevConfig(Config):
SECONDS_BETWEEN_SHUTDOWNS = "10"
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DATA_FOLDER_PATH = os.path.join(BASE_DIR, "data")
SQLALCHEMY_DATABASE_URI = f"sqlite:///{os.path.join(
BASE_DIR, DATA_FOLDER_PATH, DATABASE_FILENAME
)}"
5 changes: 0 additions & 5 deletions src/opengeodeweb_back/utils_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def validate_request(request: flask.Request, schema: dict[str, str]) -> None:

if json_data is None:
json_data = {}

try:
validate = fastjsonschema.compile(schema)
validate(json_data)
Expand Down Expand Up @@ -259,10 +258,6 @@ def generate_native_viewable_and_light_viewable_from_file(

data = geode_functions.load(geode_object, copied_full_path)

# Remplacer :
# database.session.delete(temp_data_entry)
# database.session.flush()
# Par :
session = get_session()
if session:
session.delete(temp_data_entry)
Expand Down
5 changes: 1 addition & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ def copy_data():
print("Current working directory:", os.getcwd())
print("Directory contents:", os.listdir("."))

init_database(app)
# print(list(app.blueprints.keys()))
# for rule in app.url_map.iter_rules():
# print(f"Route: {rule.rule} -> {rule.endpoint}")
init_database(db_path)


@pytest.fixture
Expand Down