From 686326fd444ed678f235dcb69cbd5f519a334681 Mon Sep 17 00:00:00 2001 From: TimmyNic Date: Mon, 2 Oct 2023 20:26:55 +1300 Subject: [PATCH] Check is_pmr_workflow when committing changes --- src/mapclient/tools/pmr/pmrtool.py | 16 +++++++++++++--- src/mapclient/view/workflow/workflowwidget.py | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/mapclient/tools/pmr/pmrtool.py b/src/mapclient/tools/pmr/pmrtool.py index 823932fd..5f36f6ad 100644 --- a/src/mapclient/tools/pmr/pmrtool.py +++ b/src/mapclient/tools/pmr/pmrtool.py @@ -124,6 +124,11 @@ class PMRTool(object): PROTOCOL = 'application/vnd.physiome.pmr2.json.0' UA = 'pmr.jsonclient.Client/0.2' + PMR_URLS = [ + "https://models.physiomeproject.org/workspace", + "https://teaching.physiomeproject.org/workspace" + ] + def __init__(self, pmr_info=None, use_external_git=False): self._termLookUpLimit = 32 self.set_info(pmr_info) @@ -387,16 +392,21 @@ def linkWorkspaceDirToUrl(self, local_workspace_dir, remote_workspace_url): # Do the writing. cmd.write_remote(workspace) - def hasDVCS(self, local_workspace_dir): + def is_pmr_workflow(self, local_workspace_dir): git_dir = os.path.join(local_workspace_dir, '.git') if os.path.isdir(git_dir): bob = get_cmd_by_name(self._git_implementation)() workspace = CmdWorkspace(local_workspace_dir, bob) - return workspace.cmd is not None + if workspace.cmd is None: + return False + + remote_workspace_url = workspace.cmd.read_remote(workspace) + url = remote_workspace_url[:remote_workspace_url.rfind('/')] + return url in self.PMR_URLS + else: return False - def commitFiles(self, local_workspace_dir, message, files): workspace = CmdWorkspace(local_workspace_dir, get_cmd_by_name(self._git_implementation)()) cmd = workspace.cmd diff --git a/src/mapclient/view/workflow/workflowwidget.py b/src/mapclient/view/workflow/workflowwidget.py index 65d5c113..2cecc86c 100644 --- a/src/mapclient/view/workflow/workflowwidget.py +++ b/src/mapclient/view/workflow/workflowwidget.py @@ -558,7 +558,7 @@ def commitChanges(self, workflowDir): om = self._main_window.model().optionsManager() pmr_info = PMR() pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT)) - if not pmr_tool.hasDVCS(workflowDir): + if not pmr_tool.is_pmr_workflow(workflowDir): # nothing to commit. return True @@ -614,7 +614,7 @@ def _setIndexerFile(self, workflow_dir): pmr_info = PMR() pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT)) - if not pmr_tool.hasDVCS(workflow_dir): + if not pmr_tool.is_pmr_workflow(workflow_dir): return try: pmr_tool.addFileToIndexer(workflow_dir, DEFAULT_WORKFLOW_ANNOTATION_FILENAME)