From 68161e085735c7d097aec807830c84e5df87c861 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Wed, 31 Dec 2014 18:21:10 -0500 Subject: [PATCH] Replace another repeated idiom in Toolbox with higher level method in toolbox.panel. --- lib/galaxy/tools/__init__.py | 20 ++++---------------- lib/galaxy/tools/toolbox/panel.py | 6 ++++++ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index 111f2b9d81b..1968113b86c 100755 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -755,10 +755,7 @@ class ToolBox( object, Dictifiable ): self._tool_tag_manager.handle_tags( tool.id, elem ) self.__add_tool( tool, load_panel_dict, panel_dict ) # Always load the tool into the integrated_panel_dict, or it will not be included in the integrated_tool_panel.xml file. - if key in integrated_panel_dict or index is None: - integrated_panel_dict[ key ] = tool - else: - integrated_panel_dict.insert( index, key, tool ) + integrated_panel_dict.update_or_append( index, key, tool ) except IOError: log.error( "Error reading tool configuration file from path: %s." % path ) except Exception: @@ -787,10 +784,7 @@ class ToolBox( object, Dictifiable ): if load_panel_dict: panel_dict[ key ] = workflow # Always load workflows into the integrated_panel_dict. - if key in integrated_panel_dict or index is None: - integrated_panel_dict[ key ] = workflow - else: - integrated_panel_dict.insert( index, key, workflow ) + integrated_panel_dict.update_or_append( index, key, workflow ) except: log.exception( "Error loading workflow: %s" % workflow_id ) @@ -799,10 +793,7 @@ class ToolBox( object, Dictifiable ): key = 'label_' + label.id if load_panel_dict: panel_dict[ key ] = label - if key in integrated_panel_dict or index is None: - integrated_panel_dict[ key ] = label - else: - integrated_panel_dict.insert( index, key, label ) + integrated_panel_dict.update_or_append( index, key, label ) def _load_section_tag_set( self, elem, tool_path, load_panel_dict, index=None ): key = elem.get( "id" ) @@ -832,10 +823,7 @@ class ToolBox( object, Dictifiable ): if load_panel_dict: self._tool_panel[ key ] = section # Always load sections into the integrated_tool_panel. - if key in self._integrated_tool_panel or index is None: - self._integrated_tool_panel[ key ] = integrated_section - else: - self._integrated_tool_panel.insert( index, key, integrated_section ) + self._integrated_tool_panel.update_or_append( index, key, integrated_section ) def _load_tooldir_tag_set(self, sub_elem, elems, tool_path, integrated_elems, load_panel_dict): directory = os.path.join( tool_path, sub_elem.attrib.get("dir") ) diff --git a/lib/galaxy/tools/toolbox/panel.py b/lib/galaxy/tools/toolbox/panel.py index 6d952d79433..c4ae1b1e522 100644 --- a/lib/galaxy/tools/toolbox/panel.py +++ b/lib/galaxy/tools/toolbox/panel.py @@ -6,6 +6,12 @@ class ToolPanelElements( odict ): used both by tool panel itself (normal and integrated) and its sections. """ + def update_or_append( self, index, key, value ): + if key in self or index is None: + self[ key ] = value + else: + self.insert( index, key, value ) + def has_tool_with_id( self, tool_id ): key = 'tool_%s' % tool_id return key in self