Skip to content

Commit

Permalink
add confirmation and explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Apr 24, 2024
1 parent d915f75 commit c6af1f3
Showing 1 changed file with 60 additions and 10 deletions.
70 changes: 60 additions & 10 deletions delete.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# AiiDAlab QauntumESPRESSO App"
"# AiiDAlab QauntumESPRESSO App\n",
"\n",
"<font color=\"red\"><b>Caution!</b></font> Deleting this job will also remove <b>all associated nodes</b>, including any related calculations and their respective results. This action is <b>irreversible</b>.\n"
]
},
{
Expand All @@ -15,28 +17,76 @@
"source": [
"import urllib.parse as urlparse\n",
"\n",
"import ipywidgets as widgets\n",
"from aiida import load_profile\n",
"from aiida.orm import load_node\n",
"from aiida.tools import delete_nodes\n",
"from IPython.display import Markdown, display\n",
"\n",
"# Load AiiDA profile\n",
"load_profile()\n",
"\n",
"# Parse the primary key from the Jupyter notebook URL\n",
"url = urlparse.urlsplit(jupyter_notebook_url) # noqa F821\n",
"query = urlparse.parse_qs(url.query)\n",
"pk = int(query['pk'][0])\n",
"\n",
"# Function to display node details\n",
"\n",
"def delete_node(pk):\n",
" load_profile()\n",
" ## delete the group\n",
" _, was_deleted = delete_nodes([pk], dry_run=False)\n",
"\n",
"def display_node_details(pk):\n",
" try:\n",
" node = load_node(pk)\n",
" print(f\"Node ID: {node.pk}\")\n",
" print(f\"Node Type: {node.process_label}\")\n",
" print(f\"Label: {node.label}\")\n",
" print(f\"Description: {node.description}\")\n",
" print(f\"Creation Time: {node.ctime}\")\n",
" except Exception as e:\n",
" print(f\"Error loading node: {str(e)}\")\n",
" return False\n",
" return True\n",
"\n",
"# Function to delete node\n",
"\n",
"\n",
"def delete_node(pk, dry_run=True):\n",
" if dry_run:\n",
" _, was_deleted = delete_nodes([pk], dry_run=True)\n",
" if was_deleted:\n",
" print(f'Dry run: Node {pk} can be deleted.')\n",
" return\n",
" \n",
" _, was_deleted = delete_nodes([pk], dry_run=False)\n",
" if was_deleted:\n",
" print(f'Node {pk} deleted successfully.')\n",
"\n",
"# User interaction for node deletion\n",
"\n",
"\n",
"def confirm_deletion(b):\n",
" if delete_confirmation.value.lower() in ['y', 'yes']:\n",
" delete_node(pk, dry_run=False)\n",
" else:\n",
" print('Deletion aborted.')\n",
"\n",
" print(f'Node {pk} deleted.')\n",
"\n",
"# Ask for confirmation\n",
"if input(f'Do you really want to delete node {pk}? [y/N] ').strip().lower() == 'y':\n",
" delete_node(pk)\n",
"# Display node details\n",
"if display_node_details(pk):\n",
" # Ask for confirmation\n",
" nodes, _ = delete_nodes([pk], dry_run=False)\n",
" display(Markdown(f'**YOU ARE ABOUT TO DELETE `{len(nodes)}` NODES! THIS CANNOT BE UNDONE!**'))\n",
" delete_confirmation = widgets.Text(\n",
" value='',\n",
" placeholder='Type \"yes\" to confirm',\n",
" description='Confirm:',\n",
" disabled=False\n",
" )\n",
" confirm_button = widgets.Button(description=\"Delete Node\")\n",
" confirm_button.on_click(confirm_deletion)\n",
" display(delete_confirmation, confirm_button)\n",
"else:\n",
" print('Deletion aborted.')"
" print(\"No valid node found for deletion.\")"
]
}
],
Expand Down

0 comments on commit c6af1f3

Please sign in to comment.