Skip to content
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 is saveable #213

Merged
merged 21 commits into from
Dec 12, 2023
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
45 changes: 19 additions & 26 deletions blueprints/blueprint_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import blueprints.tools.blueprint_crs_converter as bp_crs_converter


tools_routes = flask.Blueprint("crs_converter_routes", __name__)
tools_routes = flask.Blueprint("tools_routes", __name__)
flask_cors.CORS(tools_routes)


Expand Down Expand Up @@ -80,12 +80,9 @@ def upload_file():
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
if not os.path.exists(UPLOAD_FOLDER):
os.mkdir(UPLOAD_FOLDER)
files = flask.request.files.getlist("content")

for file in files:
filename = werkzeug.utils.secure_filename(os.path.basename(file.filename))
print(f"{filename=}")
file.save(os.path.join(UPLOAD_FOLDER, filename))
file = flask.request.files["file"]
filename = werkzeug.utils.secure_filename(os.path.basename(file.filename))
file.save(os.path.join(UPLOAD_FOLDER, filename))
return flask.make_response({"message": "File uploaded"}, 201)


Expand All @@ -103,7 +100,6 @@ def allowed_objects():
allowed_objects = geode_functions.list_geode_objects(
file_extension, flask.request.json["key"]
)

return flask.make_response({"allowed_objects": allowed_objects}, 200)


Expand All @@ -124,38 +120,34 @@ def missing_files():
os.path.join(UPLOAD_FOLDER, flask.request.json["filename"]),
)
has_missing_files = missing_files.has_missing_files()
mandatory_files = missing_files.mandatory_files
additional_files = missing_files.additional_files

mandatory_files_list = []
for mandatory_file in mandatory_files:
mandatory_files_list.append(os.path.basename(mandatory_file))
mandatory_files = []
for mandatory_file in missing_files.mandatory_files:
mandatory_files.append(os.path.basename(mandatory_file))

additional_files_list = []
for additional_file in additional_files:
additional_files_list.append(os.path.basename(additional_file))
additional_files = []
for additional_file in missing_files.additional_files:
additional_files.append(os.path.basename(additional_file))

return flask.make_response(
{
"has_missing_files": has_missing_files,
"mandatory_files": mandatory_files_list,
"additional_files": additional_files_list,
"mandatory_files": mandatory_files,
"additional_files": additional_files,
},
200,
)


with open(
"blueprints/tools/tools_converter_geographic_coordinate_systems.json", "r"
) as file:
with open("blueprints/tools_geographic_coordinate_systems.json", "r") as file:
JulienChampagnol marked this conversation as resolved.
Show resolved Hide resolved
tools_geographic_coordinate_systems_json = json.load(file)


@tools_routes.route(
tools_geographic_coordinate_systems_json["route"],
methods=tools_geographic_coordinate_systems_json["methods"],
)
def crs_converter_geographic_coordinate_systems():
def geographic_coordinate_systems():
geode_functions.validate_request(
flask.request, tools_geographic_coordinate_systems_json
)
Expand Down Expand Up @@ -183,18 +175,19 @@ def crs_converter_geographic_coordinate_systems():
methods=tools_geode_objects_and_output_extensions_json["methods"],
)
def geode_objects_and_output_extensions():
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
geode_functions.validate_request(
flask.request, tools_geode_objects_and_output_extensions_json
)
geode_objects_output_extensions = geode_functions.geode_objects_output_extensions(
flask.request.json["input_geode_object"]
data = geode_functions.load(
flask.request.json["input_geode_object"],
os.path.join(UPLOAD_FOLDER, flask.request.json["filename"]),
)
geode_objects_and_output_extensions = (
geode_functions.geode_objects_output_extensions(
flask.request.json["input_geode_object"]
flask.request.json["input_geode_object"], data
)
)

return flask.make_response(
{"geode_objects_and_output_extensions": geode_objects_and_output_extensions},
200,
Expand Down
13 changes: 2 additions & 11 deletions blueprints/tools/blueprint_crs_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,10 @@ async def crs_converter_convert_file():
flask.request.json["input_geode_object"], data, flask.request.json["output_crs"]
)

geode_functions.save(
saved_files = geode_functions.save(
flask.request.json["output_geode_object"],
data,
os.path.abspath(UPLOAD_FOLDER),
new_file_name,
)
response = flask.send_from_directory(
directory=UPLOAD_FOLDER,
path=new_file_name,
as_attachment=True,
mimetype="application/octet-binary",
)
response.headers["new-file-name"] = new_file_name
response.headers["Access-Control-Expose-Headers"] = "new-file-name"

return response
return geode_functions.send_file(UPLOAD_FOLDER, saved_files, new_file_name)
42 changes: 2 additions & 40 deletions blueprints/tools/blueprint_file_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,48 +54,10 @@ async def file_converter_convert_file():
strict_file_name = os.path.splitext(secure_filename)[0]
new_file_name = strict_file_name + "." + flask.request.json["output_extension"]

sub_folder = f"{UPLOAD_FOLDER}/{strict_file_name}/"
if os.path.exists(sub_folder):
shutil.rmtree(sub_folder)

geode_functions.save(
saved_files = geode_functions.save(
flask.request.json["output_geode_object"],
data,
os.path.abspath(UPLOAD_FOLDER),
new_file_name,
)
mimetype = "application/octet-binary"

list_exceptions = ["triangle", "vtm"]
if flask.request.json["output_extension"] in list_exceptions:
if flask.request.json["output_extension"] == "triangle":
os.mkdir(sub_folder)
os.chdir(sub_folder)
generated_files = f"{UPLOAD_FOLDER}/{strict_file_name}"
shutil.move(generated_files + ".ele", sub_folder)
shutil.move(generated_files + ".neigh", sub_folder)
shutil.move(generated_files + ".node", sub_folder)
os.chdir("..")
elif flask.request.json["output_extension"] == "vtm":
generated_files = f"{UPLOAD_FOLDER}/{strict_file_name}"
shutil.move(generated_files + ".vtm", sub_folder)
new_file_name = strict_file_name + ".zip"
mimetype = "application/zip"
with zipfile.ZipFile(f"{UPLOAD_FOLDER}/{new_file_name}", "w") as zipObj:
for folder_name, sub_folders, file_names in os.walk(sub_folder):
for flask.request.json["filename"] in file_names:
file_path = os.path.join(
folder_name, flask.request.json["filename"]
)
zipObj.write(file_path, os.path.basename(file_path))

response = flask.send_from_directory(
directory=UPLOAD_FOLDER,
path=new_file_name,
as_attachment=True,
mimetype=mimetype,
)
response.headers["new-file-name"] = new_file_name
response.headers["Access-Control-Expose-Headers"] = "new-file-name"

return response
return geode_functions.send_file(UPLOAD_FOLDER, saved_files, new_file_name)
3 changes: 2 additions & 1 deletion blueprints/tools_allowed_objects.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"type": "object",
"properties": {
"filename": {
"type": "string"
"type": "string",
"not": { "type": "null" }
},
"key": {
"type": ["string", "null"]
Expand Down
6 changes: 5 additions & 1 deletion blueprints/tools_geode_objects_and_output_extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
"properties": {
"input_geode_object": {
"type": "string"
},
"filename": {
"type": "string",
"not": { "type": "null" }
}
},
"required": ["input_geode_object"],
"required": ["input_geode_object", "filename"],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$id": "/tools/crs_converter/geographic_coordinate_systems",
"$id": "/tools/geographic_coordinate_systems",
"route": "/geographic_coordinate_systems",
"methods": ["POST"],
"type": "object",
Expand Down
3 changes: 2 additions & 1 deletion blueprints/tools_missing_files.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"type": "string"
},
"filename": {
"type": "string"
"type": "string",
"not": { "type": "null" }
}
},
"required": ["input_geode_object", "filename"],
Expand Down
93 changes: 68 additions & 25 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,94 @@
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --resolver=backtracking requirements.in
# pip-compile requirements.in
#
asgiref==3.7.2
# via flask
# via
# flask
# opengeodeweb-back
attrs==23.1.0
# via
# jsonschema
# opengeodeweb-back
# referencing
blinker==1.7.0
# via flask
# via
# flask
# opengeodeweb-back
click==8.1.7
# via flask
# via
# flask
# opengeodeweb-back
colorama==0.4.6
# via click
# via
# click
# opengeodeweb-back
flask[async]==3.0.0
# via
# -r requirements.in
# flask-cors
# opengeodeweb-back
flask-cors==4.0.0
# via -r requirements.in
geode-background==7.4.4
geode-background==7.4.7
# via
# geode-explicit
# geode-implicit
# geode-simplex
geode-common==29.0.1
geode-common==30.0.3
# via
# -r requirements.in
# geode-background
# geode-explicit
# geode-implicit
# geode-numerics
# geode-simplex
# geode-viewables
# opengeodeweb-back
geode-conversion==5.1.3
geode-conversion==5.1.6
# via
# geode-explicit
# geode-implicit
geode-explicit==4.3.5
geode-explicit==4.3.8
# via
# -r requirements.in
# geode-implicit
geode-implicit==2.4.2
geode-implicit==2.5.3
# via -r requirements.in
geode-numerics==4.1.0
geode-numerics==4.2.2
# via
# -r requirements.in
# geode-implicit
# geode-simplex
geode-simplex==6.2.4
geode-simplex==6.2.7
# via -r requirements.in
geode-viewables==2.1.3
geode-viewables==2.1.7
# via opengeodeweb-back
importlib-metadata==6.8.0
# via flask
importlib-metadata==7.0.0
# via
# flask
# opengeodeweb-back
itsdangerous==2.1.2
# via flask
# via
# flask
# opengeodeweb-back
jinja2==3.1.2
# via flask
# via
# flask
# opengeodeweb-back
jsonschema==4.20.0
# via opengeodeweb-back
jsonschema-specifications==2023.11.2
# via
# jsonschema
# opengeodeweb-back
markupsafe==2.1.3
# via
# jinja2
# opengeodeweb-back
# werkzeug
opengeode-core==14.9.3
opengeode-core==14.10.2
# via
# -r requirements.in
# geode-background
Expand All @@ -77,7 +105,7 @@ opengeode-core==14.9.3
# opengeode-inspector
# opengeode-io
# opengeodeweb-back
opengeode-geosciences==7.2.1
opengeode-geosciences==7.3.2
# via
# -r requirements.in
# geode-explicit
Expand All @@ -86,36 +114,51 @@ opengeode-geosciences==7.2.1
# opengeode-geosciencesio
# opengeode-inspector
# opengeodeweb-back
opengeode-geosciencesio==4.5.1
opengeode-geosciencesio==4.5.4
# via
# -r requirements.in
# geode-explicit
# geode-implicit
# opengeode-inspector
# opengeodeweb-back
opengeode-inspector==4.0.0
opengeode-inspector==4.0.3
# via
# -r requirements.in
# geode-explicit
# geode-implicit
# opengeodeweb-back
opengeode-io==6.2.1
opengeode-io==6.2.4
# via
# -r requirements.in
# geode-explicit
# geode-implicit
# geode-viewables
# opengeode-inspector
# opengeodeweb-back
opengeodeweb-back==2.1.0
opengeodeweb-back==3.0.0rc6
# via -r requirements.in
python-dotenv==1.0.0
# via -r requirements.in
referencing==0.31.1
# via
# jsonschema
# jsonschema-specifications
# opengeodeweb-back
rpds-py==0.13.2
# via
# jsonschema
# opengeodeweb-back
# referencing
typing-extensions==4.8.0
# via asgiref
# via
# asgiref
# opengeodeweb-back
werkzeug==3.0.1
# via
# -r requirements.in
# flask
# opengeodeweb-back
zipp==3.17.0
# via importlib-metadata
# via
# importlib-metadata
# opengeodeweb-back
Loading