Skip to content

Commit

Permalink
fix: add a check to see if simulation output exists (#199)
Browse files Browse the repository at this point in the history
Signed-off-by: olalekan temitayo <[email protected]>

Signed-off-by: olalekan temitayo <[email protected]>
Signed-off-by: Freeman <[email protected]>
  • Loading branch information
temitayopelumi authored and Freeman-kuch committed Oct 20, 2022
1 parent d6b8883 commit bb8daaa
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions local/rest_api_gcbm/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,24 @@ def gcbm_download():
title = request.form.get("title") or "simulation"
# Sanitize title
title = "".join(c for c in title if c.isalnum())

output_dir = f"{os.getcwd()}/output/{title}.zip"
input_dir = f"{os.getcwd()}/input/{title}"

# if the title has an input simulation and there is no output simulation then they should check the status.
if not os.path.exists(f"{output_dir}") and os.path.exists(f"{input_dir}"):
return {
"message": "You simulation is currently running, check the status via /gcbm/status"
}

# if there is no input simulation and no output simulation then the simulation does not exist.
elif not os.path.exists(f"{output_dir}") and not os.path.exists(f"{input_dir}"):
return {
"message": "You don't have a simulation with this title kindly check the title and try again"
}

return send_file(
f"{os.getcwd()}/output/{title}.zip",
attachment_filename="{title}.zip",
f"{os.getcwd()}/output/{title}.zip", attachment_filename="{title}.zip",
)


Expand All @@ -484,10 +499,13 @@ def gcbm_list_simulations():
for file in os.listdir(f"{os.getcwd()}/input"):
list.append(file)

return {
"data": list,
"message": "To create a new simulation, create a request at gcbm/new. To access the results of the existing simulations, create a request at gcbm/download.",
}, 200
return (
{
"data": list,
"message": "To create a new simulation, create a request at gcbm/new. To access the results of the existing simulations, create a request at gcbm/download.",
},
200,
)


@app.route("/gcbm/status", methods=["POST"])
Expand Down

0 comments on commit bb8daaa

Please sign in to comment.