Skip to content

Commit

Permalink
Delete data.
Browse files Browse the repository at this point in the history
  • Loading branch information
chStaiger committed Apr 22, 2024
1 parent f811dd0 commit 0a3c150
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 51 deletions.
67 changes: 28 additions & 39 deletions gui/IrodsBrowser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Browser tab.
"""
import logging
import sys

import irods.exception
Expand All @@ -16,8 +15,8 @@
from ibridges.meta import MetaData
from ibridges.permissions import Permissions

import gui
from gui.gui_utils import populate_table, get_irods_item
import gui.popupWidgets
from gui.gui_utils import populate_table, get_irods_item, get_coll_dict

class IrodsBrowser(PyQt6.QtWidgets.QWidget,
gui.ui_files.tabBrowser.Ui_tabBrowser):
Expand Down Expand Up @@ -70,7 +69,7 @@ def browse(self):
# Main manipulation buttons Upload/Download create collection
#self.UploadButton.clicked.connect(self.fileUpload)
#self.DownloadButton.clicked.connect(self.fileDownload)
#self.createCollButton.clicked.connect(self.createCollection)
self.createCollButton.clicked.connect(self.createCollection)

# Browser table behaviour
self.browserTable.doubleClicked.connect(self.updatePath)
Expand All @@ -86,8 +85,8 @@ def browse(self):
self.aclTable.clicked.connect(self.edit_acl)
self.aclAddButton.clicked.connect(self.update_icat_acl)
# Delete
#self.dataDeleteButton.clicked.connect(self.deleteData)
#self.loadDeleteSelectionButton.clicked.connect(self.loadSelection)
self.dataDeleteButton.clicked.connect(self.deleteData)
self.loadDeleteSelectionButton.clicked.connect(self.loadSelection)


def resetPath(self):
Expand All @@ -113,6 +112,12 @@ def updatePath(self, index):
self.inputPath.setText(str(irods_path))
self.loadBrowserTable()

def createCollection(self):
parent = IrodsPath(self.session, "/"+self.inputPath.text().strip("/"))
creteCollWidget = gui.popupWidgets.irodsCreateCollection(parent)
creteCollWidget.exec()
self.loadBrowserTable()


def loadBrowserTable(self):
"""Loads main browser table"""
Expand Down Expand Up @@ -161,7 +166,6 @@ def fillInfo(self, index):
self._fill_acls_tab(irods_path)
self._fill_replicas_tab(irods_path)
except Exception as error:
logging.error('Browser', exc_info=True)
self.errorLabel.setText(repr(error))


Expand Down Expand Up @@ -230,7 +234,7 @@ def update_icat_acl(self):
self.errorLabel.setText(
'WARNING: (no)inherit is not applicable to data objects')
return
elif user_name is "":
elif user_name == "":
self.errorLabel.setText("Please provide a user.")
return
elif acc_name == "":
Expand Down Expand Up @@ -386,27 +390,23 @@ def loadSelection(self):
self.deleteSelectionBrowser.clear()
path_name = self.inputPath.text()
row = self.browserTable.currentRow()
if row > -1:
obj_name = self.browserTable.item(row, 1).text()
obj_path = "/"+path_name.strip("/")+"/"+obj_name.strip("/")
try:
if self.conn.collection_exists(obj_path):
irodsDict = utils.utils.get_coll_dict(self.conn.get_collection(obj_path))
elif self.conn.dataobject_exists(obj_path):
irodsDict = {self.conn.get_dataobject(obj_path).path: []}
else:
self.errorLabel.setText("Load: nothing selected.")
pass
for key in list(irodsDict.keys())[:20]:
if row == -1:
self.errorLabel.setText("Please select a collection or data object.")
return
item_name = self.browserTable.item(row, 1).text()
item_path = IrodsPath(self.session, '/', *path_name.split('/'), item_name)
if item_path.exists():
item = get_irods_item(item_path)
if item_path.collection_exists():
dataDict = get_coll_dict(item)
for key in list(dataDict.keys())[:20]:
self.deleteSelectionBrowser.append(key)
if len(irodsDict[key]) > 0:
for item in irodsDict[key]:
if len(dataDict[key]) > 0:
for item in dataDict[key]:
self.deleteSelectionBrowser.append('\t'+item)
self.deleteSelectionBrowser.append('...')
except irods.exception.NetworkException:
self.errorLabel.setText(
"iRODS NETWORK ERROR: No Connection, please check network")
self.setCursor(PyQt6.QtGui.QCursor(PyQt6.QtCore.Qt.CursorShape.ArrowCursor))
else:
self.deleteSelectionBrowser.append(str(item_path))
self.setCursor(PyQt6.QtGui.QCursor(PyQt6.QtCore.Qt.CursorShape.ArrowCursor))

def deleteData(self):
Expand All @@ -422,22 +422,13 @@ def deleteData(self):
PyQt6.QtWidgets.QMessageBox.StandardButton.No)
if reply == PyQt6.QtWidgets.QMessageBox.StandardButton.Yes:
try:
if self.conn.collection_exists(deleteItem):
item = self.conn.get_collection(deleteItem)
else:
item = self.conn.get_dataobject(deleteItem)
self.conn.delete_data(item)
IrodsPath(self.session, deleteItem).remove()
self.deleteSelectionBrowser.clear()
self.loadBrowserTable()
self.errorLabel.clear()
except Exception as error:
self.errorLabel.setText("ERROR DELETE DATA: "+repr(error))

def createCollection(self):
parent = "/"+self.inputPath.text().strip("/")
creteCollWidget = gui.popupWidgets.irodsCreateCollection(parent)
creteCollWidget.exec()
self.loadBrowserTable()

def fileUpload(self):
fileSelect = PyQt6.QtWidgets.QFileDialog.getOpenFileName(self,
Expand All @@ -458,7 +449,6 @@ def fileUpload(self):
self.errorLabel.setText(
"iRODS NETWORK ERROR: No Connection, please check network")
except Exception as error:
logging.error('Upload failed %s: %r', fileSelect[0], error)
self.errorLabel.setText(repr(error))

def fileDownload(self):
Expand Down Expand Up @@ -487,7 +477,6 @@ def fileDownload(self):
self.errorLabel.setText(
"iRODS NETWORK ERROR: No Connection, please check network")
except Exception as error:
logging.error('Download failed %s/%s: %r', parent, objName, error)
self.errorLabel.setText(repr(error))


Expand All @@ -506,7 +495,7 @@ def update_icat_acl(self):
self.errorLabel.setText(
'WARNING: (no)inherit is not applicable to data objects')
return
elif user_name is "":
elif user_name == "":
self.errorLabel.setText("Please provide a user.")
return
elif acc_name == "":
Expand Down
18 changes: 18 additions & 0 deletions gui/gui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ def get_irods_item(irods_path):
except ValueError:
item = get_dataobject(irods_path.session, irods_path)
return item


def get_coll_dict(root_coll: irods.collection.iRODSCollection) -> dict:
"""Create a recursive metadata dictionary for `coll`.
Parameters
----------
root_coll : irods.collection.iRODSCollection
Root collection for the metadata gathering.
Returns
-------
dict
Keys of logical paths, values
"""
return {this_coll.path: [data_obj.name for data_obj in data_objs]
for this_coll, _, data_objs in root_coll.walk()}
20 changes: 9 additions & 11 deletions gui/popupWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from gui.ui_files.irodsIndexPopup import Ui_irodsIndexPopup

import utils
from ibridges import IrodsPath

class irodsCreateCollection(QDialog, Ui_createCollection):
context = utils.context.Context()
Expand All @@ -28,24 +29,21 @@ def __init__(self, parent):
else:
loadUi("gui/ui_files/createCollection.ui", self)

self.conn = self.context.irods_connector
self.setWindowTitle("Create iRODS collection")
self.setWindowFlags(QtCore.Qt.WindowType.WindowStaysOnTopHint)
self.parent = parent
self.label.setText(self.parent + "/")
self.label.setText(str(self.parent) + "/")
self.buttonBox.accepted.connect(self.accept)

def accept(self):
if self.collPathLine.text() != "":
newCollPath = self.parent + "/" + self.collPathLine.text()
try:
self.conn.ensure_coll(newCollPath)
self.done(1)
except Exception as error:
if hasattr(error, 'message'):
self.errorLabel.setText(error.message)
else:
self.errorLabel.setText("ERROR: insufficient rights.")
newCollPath = IrodsPath(self.parent.session, self.parent,
self.collPathLine.text())
if newCollPath.exists():
self.errorLabel.setText(f'{newCollPath} already exists.')
else:
IrodsPath.create_collection(newCollPath.session, newCollPath)
self.done(0)


class createDirectory(QDialog, Ui_createCollection):
Expand Down
2 changes: 1 addition & 1 deletion gui/ui_files/tabBrowser.ui
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ QPushButton#dataDeleteButton
<string notr="true"/>
</property>
<property name="currentIndex">
<number>2</number>
<number>4</number>
</property>
<widget class="QWidget" name="preview">
<property name="font">
Expand Down

0 comments on commit 0a3c150

Please sign in to comment.