Skip to content

Commit

Permalink
Delete runs (#537)
Browse files Browse the repository at this point in the history
* Runs can be deleted

* Fixed Comments

* gitignore modified

* gitignore modified

* gitignore modified

* fixed workflow

* Added requested Changes from Reviews

* Fixed Ui not showing properly

* Fixed Git ignore

* Fixed linebreak

* Added worklflows ordner to gitignore

* final
  • Loading branch information
gitjannes authored Nov 13, 2024
1 parent 2beaf7a commit a2d0bf6
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.idea/
user_data/runs/*
user_data/workflows/*
user_data/external_data/*
user_data/debug/*
ui/static/admin/*
Expand Down
9 changes: 9 additions & 0 deletions protzilla/run_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import threading
import traceback

import os
import shutil

import protzilla.constants.paths as paths
from protzilla.steps import Messages, Output, Plots, Step
from protzilla.utilities import format_trace
Expand All @@ -18,6 +21,12 @@ def get_available_run_names() -> list[str]:
if not directory.name.startswith(".")
]

def delete_run_folder(run_name) -> None:
path = os.path.join(paths.RUNS_PATH, run_name)

if os.path.isdir(path):
shutil.rmtree(path)


class Run:
class ErrorHandlingContextManager:
Expand Down
99 changes: 56 additions & 43 deletions ui/runs/templates/runs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

{% block content %}
<div class="container d-flex align-items-center justify-content-center" id="contain">
<div class="col" id="row">
<div class="col">
{% if messages %}
<div class="messages">
{% for message in messages %}
Expand All @@ -21,51 +21,64 @@
</div>
<br>
{% endif %}
<div class="row">
<div class="col mx-4">
<form action="{% url 'runs:create' %}" method="post">
{% csrf_token %}
<div class="mb-2">
<h3>Work on a new run:</h3>
<input name="run_name" id="run_name" placeholder="Add run name" class="form-control">
</div>
<div class="mb-2">
<label for="workflow_config_name">With workflow:</label>
<select name="workflow_config_name" id="workflow_config_name" class="form-select">
{% for name in available_workflows %}
<option value="{{ name }}" {% if name == "standard" %} selected {% endif %}>{{ name }}</option>
{% endfor %}
</select>
</div>
<div class="mb-2">
<label for="df_mode">Memory mode:</label>
<select name="df_mode" id="df_mode" class="form-select">
<option value="disk_memory" selected >standard</option>
<option value="disk">low memory</option>
</select>
</div>
<input type="submit" value="Create" class="btn btn-red">
</form>
</div>

<div class="row">
<div class="col mx-4">
<form action="{% url 'runs:create' %}" method="post">
{% csrf_token %}
<div class="mb-2">
<h3>Work on a new run:</h3>
<input name="run_name" id="run_name" placeholder="Add run name" class="form-control" required />
</div>
<div class="mb-2">
<label for="workflow_config_name">With workflow:</label>
<select name="workflow_config_name" id="workflow_config_name" class="form-select">
{% for name in available_workflows %}
<option value="{{ name }}" {% if name == "standard" %} selected {% endif %}>{{ name }}</option>
{% endfor %}
</select>
</div>
<div class="mb-2">
<label for="df_mode">Memory mode:</label>
<select name="df_mode" id="df_mode" class="form-select">
<option value="disk_memory" selected >standard</option>
<option value="disk">low memory</option>
</select>
</div>
<input type="submit" value="Create" class="btn btn-red">
</form>
</div>
<div class="col mx-4">
<form class="mb-5" action="{% url 'runs:continue' %}" method="post">
{% csrf_token %}
<div class="mb-2">
<h3>Continue an existing run:</h3>
<select name="run_name" id="run_name_option" class="form-select">
{% for name in available_runs %}
<option value="{{ name }}">{{ name }}</option>
{% endfor %}
</select>
</div>
<input type="submit" value="Continue" class="btn btn-red">
</form>
<a class="btn btn-grey" href="{% url 'databases' %}">Manage databases</a>
</div>

<div class="col mx-4">
<form class="mb-5" action="{% url 'runs:continue' %}" method="post">
{% csrf_token %}
<div class="mb-2">
<h3>Continue an existing run:</h3>
<select name="run_name" id="run_name_option" class="form-select">
{% for name in available_runs %}
<option value="{{ name }}">{{ name }}</option>
{% endfor %}
</select>
</div>
<input type="submit" value="Continue" class="btn btn-red">
</form>
<a class="btn btn-grey" href="{% url 'databases' %}">Manage databases</a>
</div>
<div class="col mx-4">
<form class="mb-5" action="{% url 'runs:delete' %}" method="post">
{% csrf_token %}
<div class="mb-2">
<h3>Delete an existing run:</h3>
<select name="run_name" id="run_name_option" class="form-select">
{% for name in available_runs %}
<option value="{{ name }}">{{ name }}</option>
{% endfor %}
</select>
</div>
<input type="submit" value="Delete" class="btn btn-red">
</form>
</div>
</div>
</div>

{% endblock %}
{% endblock %}
1 change: 1 addition & 0 deletions ui/runs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
path("", views.index, name="index"),
path("create", views.create, name="create"),
path("continue", views.continue_, name="continue"),
path("delete", views.delete_, name="delete"),
path("detail/<str:run_name>", views.detail, name="detail"),
path("<str:run_name>/plot", views.plot, name="plot"),
path("<str:run_name>/tables/<int:index>", views.tables, name="tables_nokey"),
Expand Down
36 changes: 34 additions & 2 deletions ui/runs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from django.urls import reverse
from django.conf import settings

from protzilla.run import Run, get_available_run_names
from protzilla.run import Run, get_available_run_names
from protzilla.run_v2 import delete_run_folder
from protzilla.run_helper import log_messages
from protzilla.stepfactory import StepFactory
from protzilla.steps import Step
Expand Down Expand Up @@ -231,6 +232,37 @@ def continue_(request: HttpRequest):

return HttpResponseRedirect(reverse("runs:detail", args=(run_name,)))

def delete_(request: HttpRequest):
"""
Deletes an existing run. The user is redirected to the index page.
:param request: the request object
:type request: HttpRequest
:return: the rendered details page of the run
:rtype: HttpResponse
"""
run_name = request.POST["run_name"]
if run_name in active_runs:
del active_runs[run_name]

try:
delete_run_folder(run_name)
except Exception as e:
display_message(
{
"level": 40,
"msg": f"Couldn't delete the run '{run_name}' . Please check the permissions for this file or try running Protzilla as administrator.",
"trace": format_trace(traceback.format_exception(e)),
},
request,
)
traceback.print_exc()
return HttpResponseRedirect(reverse("runs:index"))

return HttpResponseRedirect(reverse("runs:index"))


def next_(request, run_name):
"""
Expand All @@ -249,7 +281,7 @@ def next_(request, run_name):
run = active_runs[run_name]
name = request.POST.get("name", None)
if name:
run.steps.name_current_step_instance(name)
run.steps.name_current_step_instance(name)
run.step_next()

return HttpResponseRedirect(reverse("runs:detail", args=(run_name,)))
Expand Down

0 comments on commit a2d0bf6

Please sign in to comment.