Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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)
14 changes: 3 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
# 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.*,>=3.9.2
# via flask
blinker==1.*,>=1.9.0
# via flask
click==8.*,>=8.3.0
# via flask
fastjsonschema==2.*,>=2.21.1
# via opengeodeweb-microservice
flask[async]==3.0.3
# via
# -r requirements.in
Expand All @@ -21,9 +19,7 @@ flask[async]==3.0.3
flask-cors==6.*,>=6.0.1
# via -r requirements.in
flask-sqlalchemy==3.*,>=3.1.1
# via
# -r requirements.in
# opengeodeweb-microservice
# via -r requirements.in
geode-common==33.11.0
# via
# -r requirements.in
Expand Down Expand Up @@ -63,12 +59,8 @@ opengeode-io==7.4.0
# -r requirements.in
# geode-viewables
# opengeode-geosciencesio
opengeodeweb-microservice==1.*,>=1.0.0
# via -r requirements-internal.in
sqlalchemy==2.*,>=2.0.43
# via
# flask-sqlalchemy
# opengeodeweb-microservice
# via flask-sqlalchemy
typing-extensions==4.*,>=4.15.0
# via sqlalchemy
werkzeug==3.0.3
Expand Down
10 changes: 1 addition & 9 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 @@ -19,6 +16,7 @@ class Config(object):
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 +25,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 +34,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 @@ -87,7 +87,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 @@ -249,10 +248,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