From 4ef18af0840279050f00b2bf26ade309bd21a27c Mon Sep 17 00:00:00 2001 From: Julien Champagnol <91873154+JulienChampagnol@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:29:47 +0200 Subject: [PATCH] Next (#350) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add docker squash * retrigger run * add branch protection * fix : move generated directory in upload folder (#129) * PR to develop (#130) * Feature/error handling (#124) * feat(wip) : try except * update requirements * feat(wip) : refactor * fix : update requirements * fix * merge develop into feature/errors_handling * Feature/crs (#131) * feat(wip) : try except * update requirements * feat(wip) : refactor * fix : update requirements * fix * merge develop into feature/errors_handling * crs blueprint * geographic_coordinate_systems * geographic_coordinate_systems return crs_list * feat(wip) : crs_converter output_file_extensions & add crs_converter tests * update requirements * passing unit tests * explode input & output crs load model * update requirements * add send_from_directory * add is_model update requirements * fix tests and refactor * add builders * add crs key to geode_objects assign/convert * code cleanup * refactor + remove console.logs * Update requirements.txt Co-authored-by: Arnaud Botella * update crs tests * 14.1.11-rc1 * re arange functions place * start update tests * add crs_converter mesh tests * add crs=False * update requirements --------- Co-authored-by: Arnaud Botella * Fix/secure unit tests (#157) * Develop (#132) * add docker squash * retrigger run * add branch protection * fix : move generated directory in upload folder (#129) * PR to develop (#130) * Feature/error handling (#124) * feat(wip) : try except * update requirements * feat(wip) : refactor * fix : update requirements * fix * merge develop into feature/errors_handling * Feature/crs (#131) * feat(wip) : try except * update requirements * feat(wip) : refactor * fix : update requirements * fix * merge develop into feature/errors_handling * crs blueprint * geographic_coordinate_systems * geographic_coordinate_systems return crs_list * feat(wip) : crs_converter output_file_extensions & add crs_converter tests * update requirements * passing unit tests * explode input & output crs load model * update requirements * add send_from_directory * add is_model update requirements * fix tests and refactor * add builders * add crs key to geode_objects assign/convert * code cleanup * refactor + remove console.logs * Update requirements.txt Co-authored-by: Arnaud Botella * update crs tests * 14.1.11-rc1 * re arange functions place * start update tests * add crs_converter mesh tests * add crs=False * update requirements --------- Co-authored-by: Arnaud Botella --------- Co-authored-by: Arnaud Botella * add test data files * launch tests * (wip) : update tests * update unit tests * pep8 formatting * Update requirements.txt * update unit tests * add get_form_variables function * tests passing --------- Co-authored-by: Arnaud Botella * Feature refactoring (#162) * save * update passing tests * import geode_functions in app.py * opengeodeweb-back==0.0.14 * empty commit * upload before test * add filename * function upload_files() * remove tests * Add LICENSE_TOKEN * test * test wget license file * test * test * remove LICENSE_TOKEN * Feature workflows (#164) * Develop (#132) * add docker squash * retrigger run * add branch protection * fix : move generated directory in upload folder (#129) * PR to develop (#130) * Feature/error handling (#124) * feat(wip) : try except * update requirements * feat(wip) : refactor * fix : update requirements * fix * merge develop into feature/errors_handling * Feature/crs (#131) * feat(wip) : try except * update requirements * feat(wip) : refactor * fix : update requirements * fix * merge develop into feature/errors_handling * crs blueprint * geographic_coordinate_systems * geographic_coordinate_systems return crs_list * feat(wip) : crs_converter output_file_extensions & add crs_converter tests * update requirements * passing unit tests * explode input & output crs load model * update requirements * add send_from_directory * add is_model update requirements * fix tests and refactor * add builders * add crs key to geode_objects assign/convert * code cleanup * refactor + remove console.logs * Update requirements.txt Co-authored-by: Arnaud Botella * update crs tests * 14.1.11-rc1 * re arange functions place * start update tests * add crs_converter mesh tests * add crs=False * update requirements --------- Co-authored-by: Arnaud Botella --------- Co-authored-by: Arnaud Botella * Adding workflows blueprint * Updating requirements * Change BBox points input * test * update CD workflow * Changing env * Adding data files * Allowing .env file * Fix / undefined bbox points * Added grid cell size * Added venv and packages * added Web-Back lib and get_form_variables function * added Web-Back lib and get_form_variables function * Replaced all replaceable functions * Fixed form variables format * Fix : split variables * Added : workflows tests template * Fix : path name * Fix : route methods * Add : workflow ong tests + exemple set from file * Added tests + exception handling + absolute paths * Fixed exceptions + Added tests with stupid values * Fix : Dockerfile python version * Add : args to docker build + lic download * Test : secret name * test secret name * test concat * test force * test * Test : build with if/else * Fix : opengeodeweb version * deleted tests * Test : get license with curl * Fix : opengeodeweb version * Test : curl * Test : curl bis * Test : corrected version * Test with bearer * Test : curl ter * test : curl with ref * Test : curl without ref * test : curl again * Test : right file name * remove test * clean actions * Add : lock and time files requests * Fix : abspath in lock and time requests * Add : blueprints tree structure * Fix : blueprints importations * Fix : blueprints names * Fix : new routes in tests * Fix : added abspath to lock and time folders * Add : child bp imported in parents bp * Fix : importation routes * Fix : bp names * Removed lock and time folder from child bp * fix : loading data * fix : saving data * Fix : save args * Changed workflows routes names * Updated routes in tests * Delete venv directory * Delete .env * edit ignore * fixed inspector * removed before and teardown requests * Rename workflows + clean code + data folders * Added "/" before file names * Fixed "/" in file routes * Fixed data folder for tests --------- Co-authored-by: Julien Champagnol <91873154+JulienChampagnol@users.noreply.github.com> Co-authored-by: Arnaud Botella * Update port 5000 * test config * remove ID from url_prefix * remove ID in tests * Feature add viewers (#165) * better implicit workflow (#171) * better implicit workflow * fix tests * add log * remove implicit surfaces * update implicit points * update requirements * update simplex * fix tests * update explicit * fix tests * update explicit * add sharp section * update data * fix tests * fix tests * update to next branch convention * image_name: 'website-back' * /website/createbackend * update requirements * fix tests * update folders paths * Feat validation (#196) * update * update * new version of website back * update blueprint_validity_checker.py * update unit tests and requirements * update unit tests * update .env * fix unit tests * change upload_file * clean code * update .env * update content * test * remove filename * add FileStorage * file basename * os.mkdir(UPLOAD_FOLDER) --------- Co-authored-by: JulienChampagnol * Feat validation (#203) * update * update * new version of website back * update blueprint_validity_checker.py * update unit tests and requirements * update unit tests * update .env * fix unit tests * change upload_file * clean code * update .env * update content * test * remove filename * add FileStorage * file basename * os.mkdir(UPLOAD_FOLDER) --------- Co-authored-by: SpliiT * add prepare pr * Json Back - Upgrade (#206) * Json Back - Upgrade * Apply prepare changes * remove geode_objects.py * Remove useless specifications * Update opengeodeweb-back==2.0.0 * add upload file funciton * feat(tools): add missing files and class heritage (#205) Co-authored-by: Arnaud Botella Co-authored-by: Julien Champagnol <91873154+JulienChampagnol@users.noreply.github.com> Co-authored-by: JulienChampagnol Co-authored-by: SpliiT Co-authored-by: Clémentine <93268012+Clemamolette@users.noreply.github.com> Co-authored-by: Tao Schiro <106495600+SpliiT@users.noreply.github.com> Co-authored-by: JulienChampagnol fix : move generated directory in upload folder (#129) Fix/secure unit tests (#157) * fix explicit_remesh_json * Feat refactor schemas (#209) * Next (#208) Co-authored-by: Arnaud Botella Co-authored-by: Julien Champagnol <91873154+JulienChampagnol@users.noreply.github.com> Co-authored-by: JulienChampagnol Co-authored-by: SpliiT Co-authored-by: Clémentine <93268012+Clemamolette@users.noreply.github.com> Co-authored-by: Tao Schiro <106495600+SpliiT@users.noreply.github.com> Co-authored-by: JulienChampagnol * Refactoring crs_converter * rename json file * python files edited : refactoring routes --------- Co-authored-by: Julien Champagnol <91873154+JulienChampagnol@users.noreply.github.com> Co-authored-by: Arnaud Botella Co-authored-by: JulienChampagnol Co-authored-by: Clémentine <93268012+Clemamolette@users.noreply.github.com> Co-authored-by: JulienChampagnol * Feat is saveable (#213) * Next (#208) Co-authored-by: Arnaud Botella Co-authored-by: Julien Champagnol <91873154+JulienChampagnol@users.noreply.github.com> Co-authored-by: JulienChampagnol Co-authored-by: SpliiT Co-authored-by: Clémentine <93268012+Clemamolette@users.noreply.github.com> Co-authored-by: Tao Schiro <106495600+SpliiT@users.noreply.github.com> Co-authored-by: JulienChampagnol * feat(schemas): filename becomes array * update deps * deactivate workflows * feat(tools_routes): refactor routes BREAKING CHANGE: routes now can handle multiple files, filename becomes filenames * save * update requirements * move geographic_coordinate_systems to tools * update tests from api change * move geographic_coordinate_systems to tools * activate implicit * remove print * revert schemas * tools blueprint mono file * mono file output_extensions * remove prints * update tests and requirements --------- Co-authored-by: Arnaud Botella Co-authored-by: SpliiT Co-authored-by: Clémentine <93268012+Clemamolette@users.noreply.github.com> Co-authored-by: Tao Schiro <106495600+SpliiT@users.noreply.github.com> Co-authored-by: JulienChampagnol * update requirements * update ogw-back dependencies * update to opengeodeweb-back 3.0.0 * update ogw-back (#222) * update ogw-back and tests * test print * test OPTIONS * flush=True * remove prints * opengeodeweb-back 3.1.0 * Feat_bp_tools (#217) * upgrade blueprint tools and dependencies * fix some merge conflicts * update requirements * remove unused packages * opengeodeweb-back==3.2.0rc10 * cleanup --------- Co-authored-by: JulienChampagnol * opengeodeweb-back 3.2.0 * Chore/ogw back (#243) * update requirements * chore(dependencies): update ecosystem * Apply prepare changes --------- Co-authored-by: JulienChampagnol * Chore/ogw back (#244) * delete unused schemas * delete unused schemas 2 * Chore/ogw back (#247) * delete unused schemas * delete unused schemas 2 * chore(dependencies): update ecosystem * chore(dependencies): update ecosystem * Chore/ogw back (#284) * delete unused schemas * delete unused schemas 2 * chore(dependencies): update ecosystem * chore(dependencies): update ecosystem * fix(ogw_back): fix opengeodeweb_back blueprint * Feat/refactor inspector (#309) * update opengeode dependencies * feat(inspector): remove unused routes and schemas * remove unused imports * Apply prepare changes --------- Co-authored-by: JulienChampagnol * Error handler (#324) * errorhandler * ogwb 4.2 * chore(deps): update ogw_back (#329) * Chore/update ogw back (#348) * fix changes * api changes * fix imports * Apply prepare changes * opengeodeweb-back 5.1.0 before_request & teardown_request --------- Co-authored-by: JulienChampagnol * Chore/ogw back changes (#349) * remove kill_task * remove LOCK_FOLDER & TIME_FOLDER * remove ping route * update tests * Apply prepare changes --------- Co-authored-by: JulienChampagnol --------- Co-authored-by: Arnaud Botella Co-authored-by: Clémentine <93268012+Clemamolette@users.noreply.github.com> Co-authored-by: Tao Schiro <106495600+SpliiT@users.noreply.github.com> Co-authored-by: SpliiT Co-authored-by: JulienChampagnol --- app.py | 49 +---------- blueprints/ID_ping.json | 9 -- blueprints/blueprint_ID.py | 13 --- blueprints/blueprint_tools.py | 13 +-- blueprints/blueprint_workflows.py | 13 +-- blueprints/tools/blueprint_crs_converter.py | 10 +-- blueprints/tools/blueprint_file_converter.py | 10 +-- .../tools/blueprint_validity_checker.py | 78 +----------------- .../tools/validity_checker_inspect_file.json | 25 ------ .../tools/validity_checker_test_names.json | 17 ---- blueprints/workflows/blueprint_explicit.py | 10 +-- blueprints/workflows/blueprint_implicit.py | 12 +-- blueprints/workflows/blueprint_simplex.py | 6 +- config.py | 2 - requirements.in | 2 +- requirements.txt | 74 ++++++++--------- tests/test_functions.py | 5 -- tests/test_validity_checker.py | 82 ------------------- 18 files changed, 71 insertions(+), 359 deletions(-) delete mode 100644 blueprints/ID_ping.json delete mode 100644 blueprints/tools/validity_checker_inspect_file.json delete mode 100644 blueprints/tools/validity_checker_test_names.json diff --git a/app.py b/app.py index 4e12283..9e9331e 100644 --- a/app.py +++ b/app.py @@ -11,8 +11,8 @@ import blueprints.blueprint_workflows as bp_workflows import blueprints.blueprint_ID as bp_ID -from opengeodeweb_back import geode_functions from opengeodeweb_back.routes import blueprint_routes +from opengeodeweb_back.utils_functions import handle_exception, kill_task, set_interval from werkzeug.exceptions import HTTPException @@ -27,35 +27,6 @@ app = flask.Flask(__name__) -def kill_task(): - if not os.path.exists(LOCK_FOLDER): - os.mkdir(LOCK_FOLDER) - if not os.path.exists(TIME_FOLDER): - os.mkdir(TIME_FOLDER) - - if len(os.listdir(LOCK_FOLDER)) == 0: - print(f"No files in the {LOCK_FOLDER} folder, shutting down...", flush=True) - os._exit(0) - if not os.path.isfile(TIME_FOLDER + "/time.txt"): - print("'time.txt' file doesn't exist, shutting down...", flush=True) - os._exit(0) - if os.path.isfile(TIME_FOLDER + "/time.txt"): - with open(TIME_FOLDER + "/time.txt", "r") as file: - try: - last_request_time = float(file.read()) - except Exception as e: - print("error : ", str(e), flush=True) - os._exit(0) - current_time = time.time() - if (current_time - last_request_time) / 60 > MINUTES_BEFORE_TIMEOUT: - print( - "Server timed out due to inactivity, shutting down...", flush=True - ) - os._exit(0) - if os.path.isfile(LOCK_FOLDER + "/ping.txt"): - os.remove(LOCK_FOLDER + "/ping.txt") - - """ Config variables """ FLASK_DEBUG = True if os.environ.get("FLASK_DEBUG", default=None) == "True" else False @@ -68,8 +39,6 @@ def kill_task(): PORT = int(app.config.get("PORT")) ORIGINS = app.config.get("ORIGINS") SSL = app.config.get("SSL") -LOCK_FOLDER = app.config.get("LOCK_FOLDER") -TIME_FOLDER = app.config.get("TIME_FOLDER") MINUTES_BEFORE_TIMEOUT = float(app.config.get("MINUTES_BEFORE_TIMEOUT")) SECONDS_BETWEEN_SHUTDOWNS = float(app.config.get("SECONDS_BETWEEN_SHUTDOWNS")) @@ -87,24 +56,14 @@ def kill_task(): app.register_blueprint(bp_ID.ID_routes, url_prefix="/", name="ID_blueprint") - if FLASK_DEBUG == False: - geode_functions.set_interval(kill_task, SECONDS_BETWEEN_SHUTDOWNS) + set_interval(kill_task, SECONDS_BETWEEN_SHUTDOWNS) flask_cors.CORS(app, origins=ORIGINS) @app.errorhandler(HTTPException) -def handle_exception(e): - response = e.get_response() - response.data = flask.json.dumps( - { - "code": e.code, - "name": e.name, - "description": e.description, - } - ) - response.content_type = "application/json" - return response +def errorhandler(e): + return handle_exception(e) @app.route("/createbackend", methods=["POST"]) diff --git a/blueprints/ID_ping.json b/blueprints/ID_ping.json deleted file mode 100644 index 37a6bd9..0000000 --- a/blueprints/ID_ping.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$id": "/tools/ID/ping", - "route": "ping", - "methods": [ - "POST" - ], - "type": "object", - "additionalProperties": false -} \ No newline at end of file diff --git a/blueprints/blueprint_ID.py b/blueprints/blueprint_ID.py index 80f71a2..919c97a 100644 --- a/blueprints/blueprint_ID.py +++ b/blueprints/blueprint_ID.py @@ -9,8 +9,6 @@ with open("blueprints/ID_healthcheck.json") as file: ID_healthcheck_json = json.load(file) -with open("blueprints/ID_ping.json") as file: - ID_ping_json = json.load(file) ID_routes = flask.Blueprint("ID_routes", __name__) flask_cors.CORS(ID_routes) @@ -19,14 +17,3 @@ @ID_routes.route(ID_healthcheck_json["route"], methods=ID_healthcheck_json["methods"]) def root(): return flask.make_response({"message": "healthy"}, 200) - - -@ID_routes.route(ID_ping_json["route"], methods=ID_ping_json["methods"]) -def ping(): - LOCK_FOLDER = flask.current_app.config["LOCK_FOLDER"] - if not os.path.exists(LOCK_FOLDER): - os.mkdir(LOCK_FOLDER) - if not os.path.isfile(LOCK_FOLDER + "/ping.txt"): - f = open(LOCK_FOLDER + "/ping.txt", "a") - f.close() - return flask.make_response({"message": "Flask server is running"}, 200) diff --git a/blueprints/blueprint_tools.py b/blueprints/blueprint_tools.py index abb5190..96f0e8c 100644 --- a/blueprints/blueprint_tools.py +++ b/blueprints/blueprint_tools.py @@ -5,7 +5,7 @@ # Third party imports import flask import flask_cors -from opengeodeweb_back import geode_functions, geode_objects +from opengeodeweb_back import utils_functions import werkzeug import blueprints.tools.blueprint_file_converter as bp_file_converter @@ -19,19 +19,12 @@ @tools_routes.before_request def before_request(): - geode_functions.create_lock_file( - os.path.abspath(flask.current_app.config["LOCK_FOLDER"]) - ) + utils_functions.before_request(flask.current_app) @tools_routes.teardown_request def teardown_request(exception): - geode_functions.remove_lock_file( - os.path.abspath(flask.current_app.config["LOCK_FOLDER"]) - ) - geode_functions.create_time_file( - os.path.abspath(flask.current_app.config["TIME_FOLDER"]) - ) + utils_functions.teardown_request(flask.current_app) tools_routes.register_blueprint( diff --git a/blueprints/blueprint_workflows.py b/blueprints/blueprint_workflows.py index 1421f3a..1eef653 100644 --- a/blueprints/blueprint_workflows.py +++ b/blueprints/blueprint_workflows.py @@ -4,7 +4,7 @@ # Third party imports import flask import flask_cors -from opengeodeweb_back import geode_functions, geode_objects +from opengeodeweb_back import utils_functions import blueprints.workflows.blueprint_implicit as bp_implicit import blueprints.workflows.blueprint_simplex as bp_simplex @@ -16,19 +16,12 @@ @workflows_routes.before_request def before_request(): - geode_functions.create_lock_file( - os.path.abspath(flask.current_app.config["LOCK_FOLDER"]) - ) + utils_functions.before_request(flask.current_app) @workflows_routes.teardown_request def teardown_request(exception): - geode_functions.remove_lock_file( - os.path.abspath(flask.current_app.config["LOCK_FOLDER"]) - ) - geode_functions.create_time_file( - os.path.abspath(flask.current_app.config["TIME_FOLDER"]) - ) + utils_functions.teardown_request(flask.current_app) workflows_routes.register_blueprint( diff --git a/blueprints/tools/blueprint_crs_converter.py b/blueprints/tools/blueprint_crs_converter.py index 800a3b6..fd10cad 100644 --- a/blueprints/tools/blueprint_crs_converter.py +++ b/blueprints/tools/blueprint_crs_converter.py @@ -6,7 +6,7 @@ import flask import flask_cors import werkzeug -from opengeodeweb_back import geode_functions +from opengeodeweb_back import geode_functions, utils_functions import json crs_converter_routes = flask.Blueprint("crs_converter_routes", __name__) @@ -21,7 +21,7 @@ crs_converter_versions_json["route"], methods=crs_converter_versions_json["methods"] ) def crs_converter_versions(): - geode_functions.validate_request(flask.request, crs_converter_versions_json) + utils_functions.validate_request(flask.request, crs_converter_versions_json) list_packages = [ "OpenGeode-core", "OpenGeode-IO", @@ -29,7 +29,7 @@ def crs_converter_versions(): "OpenGeode-GeosciencesIO", ] return flask.make_response( - {"versions": geode_functions.versions(list_packages)}, 200 + {"versions": utils_functions.versions(list_packages)}, 200 ) @@ -42,7 +42,7 @@ def crs_converter_versions(): methods=crs_converter_convert_file_json["methods"], ) async def crs_converter_convert_file(): - geode_functions.validate_request( + utils_functions.validate_request( flask.request, crs_converter_convert_file_json, ) @@ -67,4 +67,4 @@ async def crs_converter_convert_file(): os.path.abspath(UPLOAD_FOLDER), new_file_name, ) - return geode_functions.send_file(UPLOAD_FOLDER, saved_files, new_file_name) + return utils_functions.send_file(UPLOAD_FOLDER, saved_files, new_file_name) diff --git a/blueprints/tools/blueprint_file_converter.py b/blueprints/tools/blueprint_file_converter.py index 11d698f..22d4d04 100644 --- a/blueprints/tools/blueprint_file_converter.py +++ b/blueprints/tools/blueprint_file_converter.py @@ -6,7 +6,7 @@ import flask import flask_cors import werkzeug -from opengeodeweb_back import geode_functions +from opengeodeweb_back import geode_functions, utils_functions import json @@ -23,7 +23,7 @@ methods=file_converter_versions_json["methods"], ) def file_converter_versions(): - geode_functions.validate_request(flask.request, file_converter_versions_json) + utils_functions.validate_request(flask.request, file_converter_versions_json) list_packages = [ "OpenGeode-core", "OpenGeode-IO", @@ -32,7 +32,7 @@ def file_converter_versions(): ] return flask.make_response( - {"versions": geode_functions.versions(list_packages)}, 200 + {"versions": utils_functions.versions(list_packages)}, 200 ) @@ -45,7 +45,7 @@ def file_converter_versions(): methods=file_converter_convert_file_json["methods"], ) async def file_converter_convert_file(): - geode_functions.validate_request(flask.request, file_converter_convert_file_json) + utils_functions.validate_request(flask.request, file_converter_convert_file_json) UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] secure_filename = werkzeug.utils.secure_filename(flask.request.json["filename"]) @@ -60,4 +60,4 @@ async def file_converter_convert_file(): os.path.abspath(UPLOAD_FOLDER), new_file_name, ) - return geode_functions.send_file(UPLOAD_FOLDER, saved_files, new_file_name) + return utils_functions.send_file(UPLOAD_FOLDER, saved_files, new_file_name) diff --git a/blueprints/tools/blueprint_validity_checker.py b/blueprints/tools/blueprint_validity_checker.py index b2a45e6..26ca897 100644 --- a/blueprints/tools/blueprint_validity_checker.py +++ b/blueprints/tools/blueprint_validity_checker.py @@ -1,11 +1,10 @@ # Standard library imports -import os +# # Third party imports import flask import flask_cors -import werkzeug -from opengeodeweb_back import geode_functions, inspector_functions +from opengeodeweb_back import geode_functions, utils_functions import json validity_checker_routes = flask.Blueprint("validity_checker_routes", __name__) @@ -21,7 +20,7 @@ methods=validity_checker_versions_json["methods"], ) def validity_checker_versions(): - geode_functions.validate_request(flask.request, validity_checker_versions_json) + utils_functions.validate_request(flask.request, validity_checker_versions_json) list_packages = [ "OpenGeode-core", "OpenGeode-IO", @@ -30,74 +29,5 @@ def validity_checker_versions(): "OpenGeode-Inspector", ] return flask.make_response( - {"versions": geode_functions.versions(list_packages)}, 200 - ) - - -with open("blueprints/tools/validity_checker_test_names.json", "r") as file: - validity_checker_test_names_json = json.load(file) - - -@validity_checker_routes.route( - validity_checker_test_names_json["route"], - methods=validity_checker_test_names_json["methods"], -) -def validity_checker_test_names(): - geode_functions.validate_request(flask.request, validity_checker_test_names_json) - model_checks = inspector_functions.json_return( - inspector_functions.inspectors()[flask.request.json["input_geode_object"]][ - "tests_names" - ] - ) - - return flask.make_response({"model_checks": model_checks}, 200) - - -with open("blueprints/tools/validity_checker_inspect_file.json", "r") as file: - validity_checker_inspect_file_json = json.load(file) - - -@validity_checker_routes.route( - validity_checker_inspect_file_json["route"], - methods=validity_checker_inspect_file_json["methods"], -) -def validity_checker_inspect_file(): - geode_functions.validate_request(flask.request, validity_checker_inspect_file_json) - UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"] - - secure_filename = werkzeug.utils.secure_filename(flask.request.json["filename"]) - file_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, secure_filename)) - data = geode_functions.load(flask.request.json["input_geode_object"], file_path) - inspector = geode_functions.inspector( - flask.request.json["input_geode_object"], data - ) - test_result = getattr(inspector, flask.request.json["test"])() - - if type(test_result) == int: - expected_result = 0 - elif type(test_result) == list: - expected_result = [] - elif type(test_result) == dict: - expected_result = {} - - if test_result != expected_result or type(test_result) != type(expected_result): - if type(test_result) is list: - if type(test_result[0]) is tuple: - temp_test_result = [] - for tuple_item in test_result: - temp_list = [] - for index in range(len(tuple_item)): - temp_list.append(tuple_item[index].string()) - temp_test_result.append(temp_list) - test_result = temp_test_result - result = test_result == expected_result and type(test_result) == type( - expected_result - ) - - if result is False: - test_name = flask.request.json["test"] - print(f"Wrong test result: {test_name}", flush=True) - - return flask.make_response( - {"result": result, "list_invalidities": str(test_result)}, 200 + {"versions": utils_functions.versions(list_packages)}, 200 ) diff --git a/blueprints/tools/validity_checker_inspect_file.json b/blueprints/tools/validity_checker_inspect_file.json deleted file mode 100644 index ecba7a3..0000000 --- a/blueprints/tools/validity_checker_inspect_file.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$id": "/tools/validity_checker/inspect_file", - "route": "/inspect_file", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "input_geode_object": { - "type": "string" - }, - "filename": { - "type": "string" - }, - "test": { - "type": "string" - } - }, - "required": [ - "input_geode_object", - "filename", - "test" - ], - "additionalProperties": false -} \ No newline at end of file diff --git a/blueprints/tools/validity_checker_test_names.json b/blueprints/tools/validity_checker_test_names.json deleted file mode 100644 index 764fdfc..0000000 --- a/blueprints/tools/validity_checker_test_names.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$id": "/tools/validity_checker/tests_names", - "route": "/tests_names", - "methods": [ - "POST" - ], - "type": "object", - "properties": { - "input_geode_object": { - "type": "string" - } - }, - "required": [ - "input_geode_object" - ], - "additionalProperties": false -} \ No newline at end of file diff --git a/blueprints/workflows/blueprint_explicit.py b/blueprints/workflows/blueprint_explicit.py index 545cfb3..96f25f2 100644 --- a/blueprints/workflows/blueprint_explicit.py +++ b/blueprints/workflows/blueprint_explicit.py @@ -4,7 +4,7 @@ import geode_explicit import geode_common import geode_simplex -from opengeodeweb_back import geode_functions, geode_objects +from opengeodeweb_back import geode_functions, utils_functions import flask import flask_cors import json @@ -64,9 +64,7 @@ def sendBRepStats(): "TriangulatedSurface3D", os.path.abspath(WORKFLOWS_DATA_FOLDER + "topo_good.og_tsf3d"), ) - bbox = model_A1.bounding_box() - bbox.add_box(topo.bounding_box()) - modeler = geode_explicit.BRepExplicitModeler(bbox) + modeler = geode_explicit.BRepExplicitModeler() for surface in model_A1.surfaces(): modeler.add_triangulated_surface(surface.triangulated_mesh()) modeler.add_triangulated_surface(topo) @@ -104,7 +102,7 @@ def sendBRepStats(): ) def remesh(): DATA_FOLDER = flask.current_app.config["DATA_FOLDER"] - geode_functions.validate_request(flask.request, explicit_remesh_json) + utils_functions.validate_request(flask.request, explicit_remesh_json) min_metric = 50 max_metric = 500 brep = geode_functions.load( @@ -112,7 +110,7 @@ def remesh(): ) metric = float(flask.request.json["metric"]) brep_metric = geode_common.ConstantMetric3D(metric) - brep_remeshed, _ = geode_simplex.simplex_remesh_brep(brep, brep_metric) + brep_remeshed, _ = geode_simplex.brep_simplex_remesh(brep, brep_metric) viewable_file_name = geode_functions.save_viewable( "BRep", brep_remeshed, os.path.abspath(DATA_FOLDER), "remeshed_simplex_brep" ) diff --git a/blueprints/workflows/blueprint_implicit.py b/blueprints/workflows/blueprint_implicit.py index a0d8104..a14c91d 100644 --- a/blueprints/workflows/blueprint_implicit.py +++ b/blueprints/workflows/blueprint_implicit.py @@ -10,7 +10,7 @@ import geode_implicit import geode_simplex import geode_conversion -from opengeodeweb_back import geode_functions, geode_objects +from opengeodeweb_back import geode_functions, utils_functions implicit_routes = flask.Blueprint("implicit_routes", __name__) @@ -87,7 +87,7 @@ def step0(): @implicit_routes.route(update_value_json["route"], methods=update_value_json["methods"]) def update_value(): - geode_functions.validate_request( + utils_functions.validate_request( flask.request, update_value_json, ) @@ -122,7 +122,7 @@ def update_value(): @implicit_routes.route(step1_json["route"], methods=step1_json["methods"]) def step1(): - geode_functions.validate_request( + utils_functions.validate_request( flask.request, step1_json, ) @@ -177,7 +177,7 @@ def step1(): @implicit_routes.route(step2_json["route"], methods=step2_json["methods"]) def step2(): - geode_functions.validate_request(flask.request, step2_json) + utils_functions.validate_request(flask.request, step2_json) DATA_FOLDER = flask.current_app.config["DATA_FOLDER"] implicit_model = og_geosciences.ImplicitStructuralModel( geode_functions.load( @@ -215,7 +215,7 @@ def step2(): @implicit_routes.route(step3_json["route"], methods=step3_json["methods"]) def step3(): - geode_functions.validate_request(flask.request, step3_json) + utils_functions.validate_request(flask.request, step3_json) DATA_FOLDER = flask.current_app.config["DATA_FOLDER"] extracted_cross_section = geode_functions.load( "CrossSection", os.path.abspath(DATA_FOLDER + "cross_section.og_xsctn") @@ -225,7 +225,7 @@ def step3(): extracted_cross_section, 120 ) constant_metric = geode_common.ConstantMetric2D(metric) - remeshed_section, _ = geode_simplex.simplex_remesh_section( + remeshed_section, _ = geode_simplex.section_simplex_remesh( sharp_section, constant_metric ) viewable_file_name = geode_functions.save_viewable( diff --git a/blueprints/workflows/blueprint_simplex.py b/blueprints/workflows/blueprint_simplex.py index c204bd3..2433524 100644 --- a/blueprints/workflows/blueprint_simplex.py +++ b/blueprints/workflows/blueprint_simplex.py @@ -2,7 +2,7 @@ import opengeode as geode import opengeode_io as og_io import geode_simplex -from opengeodeweb_back import geode_functions, geode_objects +from opengeodeweb_back import geode_functions, utils_functions import flask import flask_cors import json @@ -51,7 +51,7 @@ def initialize(): def remesh(): WORKFLOWS_DATA_FOLDER = flask.current_app.config["WORKFLOWS_DATA_FOLDER"] DATA_FOLDER = flask.current_app.config["DATA_FOLDER"] - variables = geode_functions.validate_request(flask.request, simplex_remesh_json) + variables = utils_functions.validate_request(flask.request, simplex_remesh_json) min_metric = 10 max_metric = 300 brep = geode_functions.load( @@ -85,7 +85,7 @@ def remesh(): ) metric = brep_metric.build_metric() - brep_remeshed, _ = geode_simplex.simplex_remesh_brep(brep, metric) + brep_remeshed, _ = geode_simplex.brep_simplex_remesh(brep, metric) viewable_file_name = geode_functions.save_viewable( "BRep", brep_remeshed, os.path.abspath(DATA_FOLDER), "remeshed_simplex_brep" ) diff --git a/config.py b/config.py index 572fbdc..213f407 100644 --- a/config.py +++ b/config.py @@ -10,8 +10,6 @@ class Config(object): CORS_HEADERS = "Content-Type" UPLOAD_FOLDER = "./uploads" WORKFLOWS_DATA_FOLDER = "./data_workflows/" - LOCK_FOLDER = "./lock/" - TIME_FOLDER = "./time/" class ProdConfig(Config): diff --git a/requirements.in b/requirements.in index bd27f3e..cce0ff5 100644 --- a/requirements.in +++ b/requirements.in @@ -2,4 +2,4 @@ python-dotenv Flask[async] Flask-Cors Werkzeug -OpenGeodeWeb-Back \ No newline at end of file +OpengeodeWeb-Back \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 43f4678..8081c83 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,19 +1,19 @@ # -# This file is autogenerated by pip-compile with Python 3.9 +# This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile --pre requirements.in +# pip-compile requirements.in # -asgiref==3.7.2 +asgiref==3.8.1 # via # flask # opengeodeweb-back -attrs==23.2.0 +attrs==24.2.0 # via # jsonschema # opengeodeweb-back # referencing -blinker==1.7.0 +blinker==1.8.2 # via # flask # opengeodeweb-back @@ -21,78 +21,73 @@ click==8.1.7 # via # flask # opengeodeweb-back -colorama==0.4.6 - # via - # click - # opengeodeweb-back -flask[async]==3.0.1 +flask[async]==3.0.3 # via # -r requirements.in # flask-cors # opengeodeweb-back -flask-cors==4.0.0 +flask-cors==4.0.1 # via # -r requirements.in # opengeodeweb-back -geode-background==7.7.1 +geode-background==8.1.1 # via # geode-explicit # geode-implicit # geode-simplex # opengeodeweb-back -geode-common==30.1.2 +geode-common==32.0.8 # via # geode-background + # geode-conversion # geode-explicit # geode-implicit # geode-numerics # geode-simplex # geode-viewables # opengeodeweb-back -geode-conversion==5.2.1 +geode-conversion==6.0.3 # via # geode-explicit # geode-implicit # opengeodeweb-back -geode-explicit==4.4.3 +geode-explicit==6.0.1 # via # geode-implicit # opengeodeweb-back -geode-implicit==2.6.1 +geode-implicit==3.1.1 # via opengeodeweb-back -geode-numerics==4.3.0 +geode-numerics==5.0.2 # via # geode-implicit # geode-simplex # opengeodeweb-back -geode-simplex==6.5.1 - # via opengeodeweb-back -geode-viewables==2.2.0 - # via opengeodeweb-back -importlib-metadata==7.0.1 +geode-simplex==8.2.1 # via - # flask + # geode-implicit # opengeodeweb-back -itsdangerous==2.1.2 +geode-viewables==3.0.0 + # via opengeodeweb-back +itsdangerous==2.2.0 # via # flask # opengeodeweb-back -jinja2==3.1.3 +jinja2==3.1.4 # via # flask # opengeodeweb-back -jsonschema==4.21.1 +jsonschema==4.23.0 # via opengeodeweb-back jsonschema-specifications==2023.12.1 # via # jsonschema # opengeodeweb-back -markupsafe==2.1.4 +markupsafe==2.1.5 # via # jinja2 # opengeodeweb-back # werkzeug -opengeode-core==14.13.2 +opengeode-core==15.2.1 # via # geode-background # geode-common @@ -107,51 +102,48 @@ opengeode-core==14.13.2 # opengeode-inspector # opengeode-io # opengeodeweb-back -opengeode-geosciences==7.4.0 +opengeode-geosciences==8.0.0 # via # geode-implicit # geode-viewables # opengeode-geosciencesio # opengeodeweb-back -opengeode-geosciencesio==4.6.0 +opengeode-geosciencesio==5.0.1 # via # geode-implicit # opengeodeweb-back -opengeode-inspector==4.0.6 +opengeode-inspector==6.0.0 # via # geode-explicit # geode-implicit + # geode-simplex # opengeodeweb-back -opengeode-io==6.4.0 +opengeode-io==7.0.1 # via # geode-implicit # geode-viewables # opengeode-geosciencesio # opengeodeweb-back -opengeodeweb-back==4.0.0 +opengeodeweb-back==5.1.0 # via -r requirements.in python-dotenv==1.0.1 # via -r requirements.in -referencing==0.33.0 +referencing==0.35.1 # via # jsonschema # jsonschema-specifications # opengeodeweb-back -rpds-py==0.17.1 +rpds-py==0.20.0 # via # jsonschema # opengeodeweb-back # referencing -typing-extensions==4.9.0 +typing-extensions==4.12.2 # via # asgiref # opengeodeweb-back -werkzeug==3.0.1 +werkzeug==3.0.3 # via # -r requirements.in # flask # opengeodeweb-back -zipp==3.17.0 - # via - # importlib-metadata - # opengeodeweb-back diff --git a/tests/test_functions.py b/tests/test_functions.py index 189e328..0d7369d 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -11,8 +11,3 @@ def test_createbackend(client): assert response.status_code == 200 ID = response.json["ID"] assert ID == "123456" - - -def test_ping(client): - response = client.post(f"/ping") - assert response.status_code == 200 diff --git a/tests/test_validity_checker.py b/tests/test_validity_checker.py index dcb68c4..08c1e18 100644 --- a/tests/test_validity_checker.py +++ b/tests/test_validity_checker.py @@ -1,7 +1,3 @@ -import os -import base64 -from werkzeug.datastructures import FileStorage - base_route = "/tools/validity_checker" @@ -12,81 +8,3 @@ def test_versions(client): assert type(versions) is list for version in versions: assert type(version) is dict - - -def test_test_names(client): - ObjectArray = [ - "BRep", - "CrossSection", - "EdgedCurve2D", - "EdgedCurve3D", - "Graph", - "HybridSolid3D", - "PointSet2D", - "PointSet3D", - "PolygonalSurface2D", - "PolygonalSurface3D", - "PolyhedralSolid3D", - "RegularGrid2D", - "RegularGrid3D", - "Section", - "StructuralModel", - "TetrahedralSolid3D", - "TriangulatedSurface2D", - "TriangulatedSurface3D", - "VertexSet", - ] - - for geode_object in ObjectArray: - # Normal test with all objects - response = client.post( - f"{base_route}/tests_names", - json={"input_geode_object": geode_object}, - ) - assert response.status_code == 200 - model_checks = response.json["model_checks"] - - assert type(model_checks) is list - for model_check in model_checks: - assert type(model_check) is dict - is_leaf = model_check["is_leaf"] - route = model_check["route"] - children = model_check["children"] - assert type(is_leaf) is bool - assert type(route) is str - assert type(children) is list - for check in children: - assert type(check) is dict - if check["is_leaf"] == True: - print("is_leaf") - response_test = client.post( - f"{base_route}/inspect_file", - json={ - "object": "BRep", - "filename": "corbi.og_brep", - "test": check["route"], - }, - ) - - assert response_test.status_code == 200 - else: - print("not is_leaf") - - -def test_inspect_file(client): - # Test with file - - filename = "corbi.og_brep" - - response = client.put( - "opengeodeweb_back/upload_file", - data={"file": FileStorage(open(f"./tests/{filename}", "rb"))}, - ) - assert response.status_code == 201 - - response = client.post( - f"{base_route}/inspect_file", - json={ - "filename": filename, - }, - )