From 67a68bce25a660f722964a5d3c1df26a8302926f Mon Sep 17 00:00:00 2001 From: chStaiger Date: Tue, 26 Nov 2024 16:03:13 +0100 Subject: [PATCH] swap md set to update, fix md delete bug (#286) * swap md set to update, fix md delete bug * ruff is rough * adjust to new meta operation * adjust browser to new metadata * switch to new ibridges release v1.3.0 --------- Co-authored-by: Staiger, Christine --- ibridgesgui/browser.py | 114 ++++++++++++++++------------- ibridgesgui/ui_files/tabBrowser.py | 2 +- ibridgesgui/ui_files/tabBrowser.ui | 2 +- pyproject.toml | 3 +- 4 files changed, 66 insertions(+), 55 deletions(-) diff --git a/ibridgesgui/browser.py b/ibridgesgui/browser.py index 5f0fba7c..78bc8dc7 100644 --- a/ibridgesgui/browser.py +++ b/ibridgesgui/browser.py @@ -2,6 +2,7 @@ import logging import sys +from typing import Union import irods.exception import PyQt6.QtCore @@ -9,7 +10,6 @@ import PyQt6.QtWidgets import PyQt6.uic from ibridges import IrodsPath -from ibridges.meta import MetaData from ibridges.permissions import Permissions from ibridges.util import obj_replicas @@ -26,7 +26,7 @@ class Browser(PyQt6.QtWidgets.QWidget, Ui_tabBrowser): """Browser view for iRODS session.""" - def __init__(self, session, app_name): + def __init__(self, session, app_name: str): """Initialize an iRODS browser view.""" super().__init__() if getattr(sys, "frozen", False): @@ -81,15 +81,15 @@ def init_browser(self): self.meta_table.clicked.connect(self.edit_metadata) self.add_meta_button.clicked.connect(self.add_icat_meta) self.add_meta_button.setToolTip("Add new metadata item.") - self.update_meta_button.clicked.connect(self.set_icat_meta) - self.update_meta_button.setToolTip("Set all entries with the same key to the new values.") + self.update_meta_button.clicked.connect(self.update_icat_meta) + self.update_meta_button.setToolTip("Update the metadata item.") self.delete_meta_button.clicked.connect(self.delete_icat_meta) self.delete_meta_button.setToolTip("Delete the metadata item.") # Manilpulate ACLs self.acl_table.clicked.connect(self.edit_permission) self.add_acl_button.clicked.connect(self.update_permission) - def update_input_path(self, irods_path): + def update_input_path(self, irods_path: Union[str, IrodsPath]): """Set the input path to a new path and loads the table.""" self.input_path.setText(str(irods_path)) # reset the params to load info tabs @@ -253,10 +253,10 @@ def fill_info_tab_content(self): self.logger.exception("Error loading %s of %s .", tab_name, irods_path) self.error_label.setText(f"Error loading {tab_name} of {irods_path}: {repr(err)}") - def set_icat_meta(self): + def update_icat_meta(self): """Button metadata set.""" try: - self._metadata_edits("set") + self._metadata_edits("update") except Exception as error: self.error_label.setText(repr(error)) @@ -275,7 +275,7 @@ def delete_icat_meta(self): self.error_label.setText(repr(error)) # @PyQt6.QtCore.pyqtSlot(PyQt6.QtCore.QModelIndex) - def edit_metadata(self, index): + def edit_metadata(self, index: PyQt6.QtCore.QModelIndex): """Load selected metadata info edit fields.""" self.error_label.clear() self.meta_key_field.clear() @@ -293,7 +293,7 @@ def edit_metadata(self, index): self.meta_units_field.setText(units) # @PyQt6.QtCore.pyqtSlot(PyQt6.QtCore.QModelIndex) - def edit_permission(self, index): + def edit_permission(self, index: PyQt6.QtCore.QModelIndex): """Load selected acl into editing fields.""" self.error_label.clear() self.acl_user_field.clear() @@ -317,10 +317,10 @@ def update_permission(self): acc_name = self.acl_box.currentText() perm_lables_to_acl = { - "Newly added items to collection will inherit permissions": "inherit", - "Remove inhertiance.": "noinherit", - "delete": "null" - } + "Newly added items to collection will inherit permissions": "inherit", + "Remove inhertiance.": "noinherit", + "delete": "null", + } if perm_lables_to_acl.get(acc_name, acc_name) in ("inherit", "noinherit"): if irods_path.dataobject_exists(): @@ -335,19 +335,29 @@ def update_permission(self): recursive = self.recursive_box.currentText() == "True" try: perm = Permissions(self.session, get_irods_item(irods_path)) - perm.set(perm=perm_lables_to_acl.get(acc_name, acc_name), - user=user_name, zone=user_zone, recursive=recursive) + perm.set( + perm=perm_lables_to_acl.get(acc_name, acc_name), + user=user_name, + zone=user_zone, + recursive=recursive, + ) if perm_lables_to_acl.get(acc_name, acc_name) == "null": self.logger.info( "Delete access (%s, %s, %s, %s) for %s", perm_lables_to_acl.get(acc_name, acc_name), - user_name, user_zone, str(recursive), str(irods_path) + user_name, + user_zone, + str(recursive), + str(irods_path), ) else: self.logger.info( "Add/change access of %s to (%s, %s, %s, %s)", - str(irods_path), perm_lables_to_acl.get(acc_name, acc_name), - user_name, user_zone, str(recursive) + str(irods_path), + perm_lables_to_acl.get(acc_name, acc_name), + user_name, + user_zone, + str(recursive), ) self._fill_acls_tab(irods_path) except (irods.exception.CAT_INVALID_USER, irods.exception.SYS_NOT_ALLOWED): @@ -367,7 +377,7 @@ def _clear_info_tabs(self): self.preview_browser.clear() self.no_meta_label.clear() - def _get_item_path(self, row): + def _get_item_path(self, row: int): item_name = self.browser_table.item(row, 1).text() return IrodsPath(self.session, "/", *self.input_path.text().split("/"), item_name) @@ -386,7 +396,7 @@ def _update_last_selected_row(self): # fill currently selected tab with info self.fill_info_tab_content() - def _fill_replicas_tab(self, irods_path): + def _fill_replicas_tab(self, irods_path: Union[IrodsPath, str]): """Populate the table in the Replicas tab. Parameters @@ -402,7 +412,7 @@ def _fill_replicas_tab(self, irods_path): self.replica_table.setRowCount(len(obj.replicas)) self.replica_table.resizeColumnsToContents() - def _fill_acls_tab(self, irods_path): + def _fill_acls_tab(self, irods_path: Union[IrodsPath, str]): """Populate the table in the ACLs tab. Parameters @@ -420,7 +430,9 @@ def _fill_acls_tab(self, irods_path): obj = None obj_acl_box_items = ["read", "write", "own", "delete"] coll_acl_box_items = obj_acl_box_items + [ - "Newly added items to collection will inherit permissions", "Remove inheritance."] + "Newly added items to collection will inherit permissions", + "Remove inheritance.", + ] if irods_path.collection_exists(): obj = irods_path.collection @@ -439,7 +451,7 @@ def _fill_acls_tab(self, irods_path): self.acl_table.resizeColumnsToContents() self.owner_label.setText(f"{obj.owner_name}") - def _fill_metadata_tab(self, irods_path): + def _fill_metadata_tab(self, irods_path: Union[IrodsPath, str]): """Populate the table in the metadata tab. Parameters @@ -452,19 +464,13 @@ def _fill_metadata_tab(self, irods_path): self.meta_value_field.clear() self.meta_units_field.clear() self.no_meta_label.clear() - item = None - if irods_path.collection_exists(): - item = irods_path.collection - elif irods_path.dataobject_exists(): - item = irods_path.dataobject - if item is not None: - meta = MetaData(item) - populate_table(self.meta_table, len(list(meta)), meta) - if len(list(meta)) == 0: + if irods_path.exists(): + populate_table(self.meta_table, len(list(irods_path.meta)), irods_path.meta) + if len(irods_path.meta) == 0: self.no_meta_label.setText(f"Metadata for {str(irods_path)} is empty.") self.meta_table.resizeColumnsToContents() - def _fill_preview_tab(self, irods_path): + def _fill_preview_tab(self, irods_path: Union[IrodsPath, str]): """Populate the table in the metadata tab. Parameters @@ -501,7 +507,7 @@ def _fill_preview_tab(self, irods_path): populate_textfield(self.preview_browser, content) self.preview_browser.verticalScrollBar().setValue(0) - def _metadata_edits(self, operation): + def _metadata_edits(self, operation: str): self.error_label.clear() if self._nothing_selected_error(): return @@ -510,23 +516,27 @@ def _metadata_edits(self, operation): new_key = self.meta_key_field.text() new_val = self.meta_value_field.text() new_units = self.meta_units_field.text() - if new_key != "" and new_val != "": - irods_path = self._get_item_path(self.browser_table.currentRow()) - if operation == "add": - irods_path.meta.add(new_key, new_val, new_units) - self.logger.info( - "Add metadata (%s, %s, %s) to %s", new_key, new_val, new_units, irods_path - ) - elif operation == "set": - irods_path.meta.set(new_key, new_val, new_units) - self.logger.info( - "Set all metadata with key %s to (%s, %s, %s) for %s", - new_key, new_key, new_val, new_units, irods_path + irods_path = self._get_item_path(self.browser_table.currentRow()) + if operation == "add": + irods_path.meta.add(new_key, new_val, new_units) + self.logger.info( + "Add metadata (%s, %s, %s) to %s", new_key, new_val, new_units, irods_path + ) + elif operation == "update": + row = self.meta_table.currentRow() + old_key = self.meta_table.item(row, 0).text() + old_val = self.meta_table.item(row, 1).text() + old_units = self.meta_table.item(row, 2).text() + print(old_key, old_val, old_units) + self.logger.info( + "Update metadata of %s from (%s, %s, %s) to (%s, %s, %s)", + irods_path, old_key, old_val, old_units, + new_key, new_val, new_units, ) - elif operation == "delete": - irods_path.meta.delete(new_key, new_val, new_units) - self.logger.info( - "Delete metadata (%s, %s, %s) from %s", - new_key, new_val, new_units, irods_path + irods_path.meta[old_key, old_val, old_units] = [new_key, new_val, new_units] + elif operation == "delete": + irods_path.meta.delete(new_key, new_val, new_units) + self.logger.info( + "Delete metadata (%s, %s, %s) from %s", new_key, new_val, new_units, irods_path ) - self._fill_metadata_tab(irods_path) + self._fill_metadata_tab(irods_path) diff --git a/ibridgesgui/ui_files/tabBrowser.py b/ibridgesgui/ui_files/tabBrowser.py index e7861fde..2bc38690 100644 --- a/ibridgesgui/ui_files/tabBrowser.py +++ b/ibridgesgui/ui_files/tabBrowser.py @@ -405,7 +405,7 @@ def retranslateUi(self, tabBrowser): self.delete_meta_button.setText(_translate("tabBrowser", "Delete")) self.label_4.setText(_translate("tabBrowser", "Key")) self.label_3.setText(_translate("tabBrowser", "Edit")) - self.update_meta_button.setText(_translate("tabBrowser", "Set all keys ..")) + self.update_meta_button.setText(_translate("tabBrowser", "Update")) self.label_6.setText(_translate("tabBrowser", "Value")) self.info_tabs.setTabText(self.info_tabs.indexOf(self.metadata), _translate("tabBrowser", "Metadata")) self.info_tabs.setTabText(self.info_tabs.indexOf(self.preview), _translate("tabBrowser", "Preview")) diff --git a/ibridgesgui/ui_files/tabBrowser.ui b/ibridgesgui/ui_files/tabBrowser.ui index 052b0465..a8c70d66 100644 --- a/ibridgesgui/ui_files/tabBrowser.ui +++ b/ibridgesgui/ui_files/tabBrowser.ui @@ -444,7 +444,7 @@ QTabWidget#info_tabs - Set all keys .. + Update diff --git a/pyproject.toml b/pyproject.toml index ed3ec996..899a5a44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,8 @@ classifiers = [ dependencies = [ "PyQt6>=6.4.2", - "ibridges>=1.2.0, < 1.3", + + "ibridges>=1.3.0, < 1.4", "setproctitle==1.3.4", "importlib-resources;python_version<='3.10'", ]