-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/folder path #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/folder path #166
Changes from 41 commits
6223aab
878be26
d626e4a
7847778
8017752
e6e3755
9d7ea19
cf9589a
5605db7
c1d3a9b
cd7d83f
d504bc8
12bff86
9027f76
7451bf7
7061126
a734e8a
061ecf4
5d13ad8
500906d
0e7d610
01469ec
a0022d8
6544070
b312038
5ebb91d
4c19434
1ccfa9b
eddbc9c
b0c91a2
6085729
e8596a3
1c3305c
01fa755
a3c4016
d37e32a
4d9f503
094b85e
5612c04
5a81dd2
86d0a0c
5195202
605b59e
e74b50f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| # Third party imports | ||
| import opengeode_geosciences as og_gs | ||
| import opengeode as og | ||
| import werkzeug | ||
| import flask | ||
|
|
||
| # Local application imports | ||
| from .geode_objects import geode_objects_dict | ||
|
|
@@ -38,6 +40,26 @@ def load(geode_object: str, file_absolute_path: str): | |
| return geode_object_value(geode_object)["load"](file_absolute_path) | ||
|
|
||
|
|
||
| def data_file_path(request_json, filename): | ||
| data_folder_path = flask.current_app.config["DATA_FOLDER_PATH"] | ||
| return os.path.join( | ||
| data_folder_path, | ||
| request_json["id"], | ||
| werkzeug.utils.secure_filename(filename), | ||
| ) | ||
|
|
||
|
|
||
| def load_data(geode_object: str, request_json: dict): | ||
|
||
| file_absolute_path = data_file_path(request_json, request_json["filename"]) | ||
| return load(geode_object, file_absolute_path) | ||
|
|
||
|
|
||
| def upload_file_path(filename): | ||
| upload_folder = flask.current_app.config["UPLOAD_FOLDER"] | ||
| secure_filename = werkzeug.utils.secure_filename(filename) | ||
| return os.path.abspath(os.path.join(upload_folder, secure_filename)) | ||
|
|
||
|
|
||
| def is_saveable(geode_object: str, data, filename: str): | ||
| return geode_object_value(geode_object)["is_saveable"](data, filename) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,36 +18,30 @@ | |
| ) | ||
| def uuid_to_flat_index(): | ||
| utils_functions.validate_request(flask.request, vtm_component_indices_json) | ||
| vtm_file_path = os.path.join( | ||
| flask.current_app.config["DATA_FOLDER_PATH"], flask.request.json["id"] + ".vtm" | ||
| ) | ||
| tree = ET.parse(vtm_file_path) | ||
| try: | ||
| vtm_file_path = geode_functions.data_file_path( | ||
| flask.request.json, | ||
| "viewable.vtm", | ||
| ) | ||
| tree = ET.parse(vtm_file_path) | ||
| except FileNotFoundError: | ||
| return flask.make_response({"error": "VTM file not found"}, 404) | ||
|
||
| root = tree.find("vtkMultiBlockDataSet") | ||
| uuid_to_flat_index = {} | ||
| current_index = 0 | ||
|
|
||
| for elem in root.iter(): | ||
| if "uuid" in elem.attrib and elem.tag == "DataSet": | ||
| uuid_to_flat_index[elem.attrib["uuid"]] = current_index | ||
|
|
||
| current_index += 1 | ||
|
|
||
| return flask.make_response( | ||
| {"uuid_to_flat_index": uuid_to_flat_index}, | ||
| 200, | ||
| ) | ||
| return flask.make_response({"uuid_to_flat_index": uuid_to_flat_index}, 200) | ||
|
|
||
|
|
||
| def extract_model_uuids(geode_object, file_path): | ||
| model = geode_functions.load(geode_object, file_path) | ||
| def extract_model_uuids(model): | ||
| mesh_components = model.mesh_components() | ||
|
|
||
| uuid_dict = {} | ||
|
|
||
| for mesh_component, ids in mesh_components.items(): | ||
| component_name = mesh_component.get() | ||
| uuid_dict[component_name] = [id.string() for id in ids] | ||
|
|
||
| return uuid_dict | ||
|
|
||
|
|
||
|
|
@@ -58,10 +52,12 @@ def extract_model_uuids(geode_object, file_path): | |
| @routes.route(mesh_components_json["route"], methods=mesh_components_json["methods"]) | ||
| def extract_uuids_endpoint(): | ||
| utils_functions.validate_request(flask.request, mesh_components_json) | ||
| file_path = os.path.join( | ||
| flask.current_app.config["DATA_FOLDER_PATH"], flask.request.json["filename"] | ||
| ) | ||
| if not os.path.exists(file_path): | ||
| try: | ||
| model = geode_functions.load_data( | ||
| flask.request.json["geode_object"], | ||
| flask.request.json, | ||
| ) | ||
| except FileNotFoundError: | ||
|
||
| return flask.make_response({"error": "File not found"}, 404) | ||
| uuid_dict = extract_model_uuids(flask.request.json["geode_object"], file_path) | ||
| uuid_dict = extract_model_uuids(model) | ||
| return flask.make_response({"uuid_dict": uuid_dict}, 200) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
j'ai vu pourquoi tu avais besoin du filename, mais du coup je trouve ca dommage de devoir donner la requete ET le filename. Dans ce cas, je dirais plutot donner l'id et le filename