Skip to content

Commit

Permalink
swap md set to update, fix md delete bug (#286)
Browse files Browse the repository at this point in the history
* 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 <christine.staiger@wur.nl>
  • Loading branch information
chStaiger and Staiger, Christine authored Nov 26, 2024
1 parent 7e03ce0 commit 67a68bc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 55 deletions.
114 changes: 62 additions & 52 deletions ibridgesgui/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import logging
import sys
from typing import Union

import irods.exception
import PyQt6.QtCore
import PyQt6.QtGui
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

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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():
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
2 changes: 1 addition & 1 deletion ibridgesgui/ui_files/tabBrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion ibridgesgui/ui_files/tabBrowser.ui
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ QTabWidget#info_tabs
</font>
</property>
<property name="text">
<string>Set all keys ..</string>
<string>Update</string>
</property>
</widget>
</item>
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
]
Expand Down

0 comments on commit 67a68bc

Please sign in to comment.