From 00ff7cdaae9ac28bb8408bd6c9345810f26d78e7 Mon Sep 17 00:00:00 2001 From: Daniel Schreij Date: Mon, 6 Mar 2017 12:12:31 -0400 Subject: [PATCH] Bump to 1.1.1 - Prevents possible pending actions for a previous experiment still being executed after opening a new one. --- .../OpenScienceFramework.py | 88 +++++++++++-------- .../OpenScienceFramework/info.yaml | 2 +- 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/opensesame_extensions/OpenScienceFramework/OpenScienceFramework.py b/opensesame_extensions/OpenScienceFramework/OpenScienceFramework.py index bad081c..20f7283 100644 --- a/opensesame_extensions/OpenScienceFramework/OpenScienceFramework.py +++ b/opensesame_extensions/OpenScienceFramework/OpenScienceFramework.py @@ -704,47 +704,54 @@ def event_save_experiment(self, path): def event_open_experiment(self, path): """ Check if opened experiment is linked to the OSF and set parameters accordingly """ + # Only take action if user is logged in - if self.manager.logged_in_user: - # Check if exp is linked to OSF. - # If so, display this information in the OSF explorer. - if self.experiment.var.has('osf_id'): - self.manager.get_file_info(self.experiment.osf_id, - self.__process_file_info) - else: - # Reset GUI if no osf_id is present - self.set_linked_experiment(None) + if not self.manager.logged_in_user: + # If user is not logged in, issue a warning on opening that a link to + # the OSF has been detected, but no syncing can occur as long is the user + # is not logged in. + if self.experiment.var.has('osf_id') or \ + self.experiment.var.has('osf_datanode_id'): + self.notifier.info(_(u'OSF link detected'), + _(u'This experiment is linked to the Open Science Framework. ' + 'Please login if you want to use the synchronization functionalities')) + self.sync_check_required = True + return - # Check if a node to upload data to has been linked for this experiment - # If so, display this information in the OSF explorer. - if self.experiment.var.has('osf_datanode_id'): - # Ids for root level locations (i.e. the root of repository) differ - # from those of subfolder locations. Both require a different API call - # to get the same kind of information, so construct those accordingly - # A root level location will contain a colon. - if not ":" in self.experiment.var.osf_datanode_id: - self.manager.get_file_info(self.experiment.osf_datanode_id, - self.__process_datafolder_info) - else: - project_id, repo = self.experiment.var.osf_datanode_id.split(':') - # For the OSF - api_call = osf.api_call('repo_files', project_id, repo) - self.__process_datafolder_info(api_call) + # If a new experiment has been opened, cancel any actions that may be + # pending of a previous experiment. + self.manager.clear_pending_requests() + + # Check if exp is linked to OSF. + # If so, display this information in the OSF explorer. + if self.experiment.var.has('osf_id'): + self.manager.get_file_info(self.experiment.osf_id, + self.__process_file_info) + else: + # Reset GUI if no osf_id is present + self.set_linked_experiment(None) + + # Check if a node to upload data to has been linked for this experiment + # If so, display this information in the OSF explorer. + if self.experiment.var.has('osf_datanode_id'): + # Ids for root level locations (i.e. the root of repository) differ + # from those of subfolder locations. Both require a different API call + # to get the same kind of information, so construct those accordingly + # A root level location will contain a colon. + if not ":" in self.experiment.var.osf_datanode_id: + self.manager.get_file_info(self.experiment.osf_datanode_id, + self.__process_datafolder_info) else: - # Reset GUI if this data is not present - self.set_linked_experiment_datanode(None) - # Refresh contents of the tree so linked items will be marked. - if not self.project_tree.isRefreshing: - self.project_tree.refresh_contents() - # If user is not logged in, issue a warning on opening that a linkt to - # the OSF has been detected, but no syncing can occur as long is the user - # is not logged in. - elif self.experiment.var.has('osf_id') or \ - self.experiment.var.has('osf_datanode_id'): - self.notifier.info(_(u'OSF link detected'), - _(u'This experiment is linked to the Open Science Framework. ' - 'Please login if you want to use the synchronization functionalities')) - self.sync_check_required = True + project_id, repo = self.experiment.var.osf_datanode_id.split(':') + # For the OSF + api_call = osf.api_call('repo_files', project_id, repo) + self.__process_datafolder_info(api_call) + else: + # Reset GUI if this data is not present + self.set_linked_experiment_datanode(None) + # Refresh contents of the tree so linked items will be marked. + if not self.project_tree.isRefreshing: + self.project_tree.refresh_contents() def event_process_data_files(self, data_files): """ See if datafiles need to be saved to OSF """ @@ -1153,6 +1160,11 @@ def __process_file_info(self, reply): '{}'.format(e)) return + # If the user doesn't have write access to the experiment, unlink it from + # the OSF. This can be the case if the user opens an experiment from a + # linked repository of another owner to which there is no write access. + + self.set_linked_experiment(osf_file_path) # See if always upload experiment flag has been set in the experiment if self.experiment.var.has('osf_always_upload_experiment') and \ diff --git a/opensesame_extensions/OpenScienceFramework/info.yaml b/opensesame_extensions/OpenScienceFramework/info.yaml index 0078a93..0322f9f 100644 --- a/opensesame_extensions/OpenScienceFramework/info.yaml +++ b/opensesame_extensions/OpenScienceFramework/info.yaml @@ -1,5 +1,5 @@ label: OSF -version: 1.1.0 +version: 1.1.1 author: Daniel Schreij link : https://github.com/dschreij/opensesame-osf