diff --git a/README.md b/README.md index db692489..f5748717 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# iBridges +# iBridges GUI
diff --git a/ibridgesgui/browser.py b/ibridgesgui/browser.py index 90473880..5f0fba7c 100644 --- a/ibridgesgui/browser.py +++ b/ibridgesgui/browser.py @@ -332,7 +332,7 @@ def update_permission(self): elif acc_name == "": self.error_label.setText("Please provide an access level from the menu.") return - recursive = self.recurisive_box.currentText() == "True" + 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), diff --git a/ibridgesgui/config.py b/ibridgesgui/config.py index 48eb8056..d429053a 100644 --- a/ibridgesgui/config.py +++ b/ibridgesgui/config.py @@ -177,7 +177,7 @@ def is_session_from_config(session: Session) -> Union[Session, None]: return False -def check_irods_config(ienv: Union[Path, dict]) -> str: +def check_irods_config(ienv: Union[Path, dict], include_network = True) -> str: """Check whether an iRODS configuration file is correct. Parameters @@ -185,6 +185,10 @@ def check_irods_config(ienv: Union[Path, dict]) -> str: ienv : Path or dict Path to the irods_environment.json or the dictionary conatining the json. + include_network : bool + If true connect to server and check more parameters. Otherwise only + existence of parameters in the environment.json will be checked. + Returns ------- str : @@ -213,43 +217,44 @@ def check_irods_config(ienv: Union[Path, dict]) -> str: return 'Please set an "irods_default_resource".' if not isinstance(env["irods_port"], int): return '"irods_port" needs to be an integer, remove quotes.' - if not Session.network_check(env["irods_host"], env["irods_port"]): - return f'No connection: Network might be down or\n \ - server name {env["irods_host"]} is incorrect or\n \ - port {env["irods_port"]} is incorrect.' - # check authentication scheme - try: - sess = iRODSSession(password="bogus", **env) - _ = sess.server_version - except TypeError as err: - return repr(err) - except NetworkException as err: - return repr(err) - except AttributeError as err: - return repr(err) - except PamLoginException as err: - # irods4.3+ specific - return f'Adjust "irods_authentication_scheme" {err.args}' - except ModuleNotFoundError as err: - # irods4.3+ uses string in authenticationscheme as class - return f'"irods_authentication_scheme": "{err.name}" does not exist' - - except PlainTextPAMPasswordError: - return ( - 'Value of "irods_client_server_negotiation" needs to be' - + ' "request_server_negotiation".' - ) - - except CAT_INVALID_AUTHENTICATION: - return 'Wrong "irods_authentication_scheme".' - except ValueError as err: - if "scheme" in err.args[0]: - return 'Value of "irods_authentication_scheme" not recognised.' - return f"{err.args}" - - # password incorrect but rest is fine - except (CAT_INVALID_USER, PAM_AUTH_PASSWORD_FAILED): - return "All checks passed successfully." + if include_network: + if not Session.network_check(env["irods_host"], env["irods_port"]): + return f'No connection: Network might be down or\n \ + server name {env["irods_host"]} is incorrect or\n \ + port {env["irods_port"]} is incorrect.' + # check authentication scheme + try: + sess = iRODSSession(password="bogus", **env) + _ = sess.server_version + except TypeError as err: + return repr(err) + except NetworkException as err: + return repr(err) + except AttributeError as err: + return repr(err) + except PamLoginException as err: + # irods4.3+ specific + return f'Adjust "irods_authentication_scheme" {err.args}' + except ModuleNotFoundError as err: + # irods4.3+ uses string in authenticationscheme as class + return f'"irods_authentication_scheme": "{err.name}" does not exist' + + except PlainTextPAMPasswordError: + return ( + 'Value of "irods_client_server_negotiation" needs to be' + + ' "request_server_negotiation".' + ) + + except CAT_INVALID_AUTHENTICATION: + return 'Wrong "irods_authentication_scheme".' + except ValueError as err: + if "scheme" in err.args[0]: + return 'Value of "irods_authentication_scheme" not recognised.' + return f"{err.args}" + + # password incorrect but rest is fine + except (CAT_INVALID_USER, PAM_AUTH_PASSWORD_FAILED): + return "All checks passed successfully." # all tests passed return "All checks passed successfully." diff --git a/ibridgesgui/login.py b/ibridgesgui/login.py index fb47e44c..68b2903e 100644 --- a/ibridgesgui/login.py +++ b/ibridgesgui/login.py @@ -13,6 +13,7 @@ from ibridgesgui.config import ( IRODSA, + check_irods_config, get_last_ienv_path, get_prev_settings, save_current_settings, @@ -83,15 +84,24 @@ def _check_home(self, session): return True def _check_resource(self, session): - resc = Resources(session).get_resource(session.default_resc) - if resc.parent is not None: + try: + resc = Resources(session).get_resource(session.default_resc) + if resc.parent is not None: + return False + return True + except Exception: return False - return True def login_function(self): """Connect to iRODS server with gathered info.""" self.error_label.clear() env_file = self.irods_config_dir.joinpath(self.envbox.currentText()) + + msg = check_irods_config(env_file, include_network = False) + if not msg == "All checks passed successfully.": + self.error_label.setText("Go to menu Configure. "+msg) + return + try: if self.cached_pw is True and self.password_field.text() == "***********": self.logger.debug("Login with %s and cached password.", env_file) @@ -116,10 +126,12 @@ def login_function(self): self.close() elif not self._check_home(session): self.error_label.setText(f'"irods_home": "{session.home}" does not exist.') + return elif not self._check_resource(session): self.error_label.setText( f'"irods_default_resource": "{session.default_resc}" not writeable.' ) + return except LoginError: self.error_label.setText("irods_environment.json not setup correctly.") diff --git a/ibridgesgui/popup_widgets.py b/ibridgesgui/popup_widgets.py index 9354d1a6..a009fe85 100644 --- a/ibridgesgui/popup_widgets.py +++ b/ibridgesgui/popup_widgets.py @@ -392,7 +392,8 @@ def _finish_upload(self): def _upload_status(self, state): up_size, transferred_size, obj_count, num_objs, obj_failed = state - self.progress_bar.setValue(int(transferred_size*100/up_size)) + if up_size > 0: + self.progress_bar.setValue(int(transferred_size*100/up_size)) text = f"{obj_count} of {num_objs} files; failed: {obj_failed}." self.error_label.setText(text) @@ -559,7 +560,8 @@ def _finish_download(self): def _download_status(self, state): down_size, transferred_size, obj_count, num_objs, obj_failed = state - self.progress_bar.setValue(int(transferred_size*100/down_size)) + if down_size > 0: + self.progress_bar.setValue(int(transferred_size*100/down_size)) text = f"{obj_count} of {num_objs} files; failed: {obj_failed}." self.error_label.setText(text) diff --git a/ibridgesgui/sync.py b/ibridgesgui/sync.py index 06223363..3bb3f5e1 100644 --- a/ibridgesgui/sync.py +++ b/ibridgesgui/sync.py @@ -268,7 +268,8 @@ def _sync_data_end(self, thread_output: dict): def _sync_data_status(self, state): up_size, transferred_size, obj_count, num_objs, obj_failed = state - self.progress_bar.setValue(int(transferred_size*100/up_size)) + if up_size > 0: + self.progress_bar.setValue(int(transferred_size*100/up_size)) text = f"{obj_count} of {num_objs} files; failed: {obj_failed}." self.error_label.setText(text)