Skip to content

Commit

Permalink
Check existance and writability of default_resource (#212)
Browse files Browse the repository at this point in the history
* Check existance and writability of default_resource

* Cleaner checks

* Bugfix

---------

Co-authored-by: Staiger, Christine <christine.staiger@wur.nl>
  • Loading branch information
chStaiger and Staiger, Christine authored Jun 26, 2024
1 parent fe2d83e commit 13f4bbd
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions ibridgesgui/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from pathlib import Path

from ibridges import IrodsPath, Session
from ibridges.resources import Resources
from ibridges.session import LoginError, PasswordError
from irods.exception import ResourceDoesNotExist
from PyQt6.QtWidgets import QDialog, QLineEdit
from PyQt6.uic import loadUi

Expand Down Expand Up @@ -84,6 +86,7 @@ def login_function(self):
session.home,
)
session.write_pam_password()
self.session_dict["session"] = session
set_last_ienv_path(env_file.name)
except LoginError:
self.error_label.setText("irods_environment.json not setup correctly.")
Expand All @@ -102,9 +105,29 @@ def login_function(self):
self.error_label.setText(f"Login failed, consult the log file(s) in {log_path}")

#check irods_home
if not IrodsPath(session).collection_exists():
fail_home = True
if not IrodsPath(self.session_dict["session"]).collection_exists():
self.error_label.setText(f'"irods_home": "{session.home}" does not exist.')
self.logger.error("irods_home does not exist.")
else:
self.session_dict["session"] = session
fail_home = False

#check existance of default resource
fail_resc = True
try:
resc = Resources(self.session_dict["session"]).get_resource(session.default_resc)
if resc.parent is None:
fail_resc = False
else:
self.error_label.setText(f'"default_resource": "{session.default_resc}" not valid.')
except ResourceDoesNotExist:
self.error_label.setText(
f'"default_resource": "{session.default_resc}" does not exist.')
self.logger.error("Default resource does not exist.")
except AttributeError:
self.error_label.setText(f'"default_resource": "{session.default_resc}" not valid.')

if fail_resc or fail_home:
del self.session_dict["session"]
else:
self.close()

0 comments on commit 13f4bbd

Please sign in to comment.