From 3fa17f706818e1aecec09fc6fa829c88d45c8578 Mon Sep 17 00:00:00 2001 From: Dave Bouvier Date: Tue, 22 Dec 2020 15:43:13 -0500 Subject: [PATCH 1/6] Stop making new sections for every toolshed tool. This change will place a newly installed toolshed tool, if the target section exists, in that previously defined section in the shed_tool_conf file. Previously the section would simply be placed at the very end, whether or not that section already existed in the XML. --- .../galaxy_install/tools/tool_panel_manager.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py index 5e438bb6b2f..8e2d7e16716 100644 --- a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py @@ -56,7 +56,21 @@ class ToolPanelManager: config_elems.append(elem) # Add the new elements to the in-memory list of config_elems. for elem_entry in elem_list: - config_elems.append(elem_entry) + section_found = False + if elem_entry.tag == 'section': + # See if there is already a section with a matching ID + for existing_elem in config_elems: + if existing_elem.tag == 'section' and existing_elem.attrib.get('id', None) == elem_entry.attrib.get('id', None): + section_found = True + for child in elem_entry: + existing_elem.append(child) + break + if section_found: + break + if not section_found: + config_elems.append(elem_entry) + else: + config_elems.append(elem_entry) # Persist the altered shed_tool_config file. self.config_elems_to_xml_file(config_elems, shed_tool_conf, tool_path, tool_cache_data_dir) self.app.wait_for_toolbox_reload(old_toolbox) From 816dd8be163f9b5880dac9605baee0250895d972 Mon Sep 17 00:00:00 2001 From: Dave Bouvier Date: Tue, 5 Jan 2021 09:52:15 -0500 Subject: [PATCH 2/6] Remove a break that shouldn't be there, add comments. --- .../tool_shed/galaxy_install/tools/tool_panel_manager.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py index 8e2d7e16716..f451f6e7cf1 100644 --- a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py @@ -58,13 +58,14 @@ class ToolPanelManager: for elem_entry in elem_list: section_found = False if elem_entry.tag == 'section': - # See if there is already a section with a matching ID + # See if there is already a section with a matching ID. for existing_elem in config_elems: if existing_elem.tag == 'section' and existing_elem.attrib.get('id', None) == elem_entry.attrib.get('id', None): section_found = True + # We've found a section, append everything from this
tag to the one in memory. for child in elem_entry: existing_elem.append(child) - break + # And jump to the next incoming section. if section_found: break if not section_found: From e03165ad414435ada4dd81fcc6481e5e960f8df9 Mon Sep 17 00:00:00 2001 From: Dave Bouvier Date: Fri, 8 Jan 2021 09:25:17 -0500 Subject: [PATCH 3/6] Simplify logic slightly, add more comments. --- .../galaxy_install/tools/tool_panel_manager.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py index f451f6e7cf1..e76aa6366f2 100644 --- a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py @@ -56,20 +56,24 @@ class ToolPanelManager: config_elems.append(elem) # Add the new elements to the in-memory list of config_elems. for elem_entry in elem_list: + # Initialize section_found to False. section_found = False if elem_entry.tag == 'section': - # See if there is already a section with a matching ID. + # Loop through section entries in the in-memory tool panel. for existing_elem in config_elems: + # Compare the section ID for each one to the section ID for the tool being installed. if existing_elem.tag == 'section' and existing_elem.attrib.get('id', None) == elem_entry.attrib.get('id', None): + # We've found a section, set section_found to True so the subsequent if statement won't append it to the end. section_found = True - # We've found a section, append everything from this
tag to the one in memory. for child in elem_entry: existing_elem.append(child) - # And jump to the next incoming section. - if section_found: - break + # Break out of the config_elems loop back to the elem_list loop so that section_found is reset to False + # and we can process the next section, if any. + break + # If an existing section with a matching ID was not found, create that section and its tools. if not section_found: config_elems.append(elem_entry) + # This is not a section, but a tool or label. No need to search for matching sections, just add it. else: config_elems.append(elem_entry) # Persist the altered shed_tool_config file. From 7ca7f74af80a4136e6df9e9ccf253948b19e2567 Mon Sep 17 00:00:00 2001 From: Dave Bouvier Date: Fri, 8 Jan 2021 09:29:53 -0500 Subject: [PATCH 4/6] Simplify logic even further. --- .../galaxy_install/tools/tool_panel_manager.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py index e76aa6366f2..94fc336d23a 100644 --- a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py @@ -56,23 +56,18 @@ class ToolPanelManager: config_elems.append(elem) # Add the new elements to the in-memory list of config_elems. for elem_entry in elem_list: - # Initialize section_found to False. - section_found = False if elem_entry.tag == 'section': # Loop through section entries in the in-memory tool panel. for existing_elem in config_elems: # Compare the section ID for each one to the section ID for the tool being installed. if existing_elem.tag == 'section' and existing_elem.attrib.get('id', None) == elem_entry.attrib.get('id', None): # We've found a section, set section_found to True so the subsequent if statement won't append it to the end. - section_found = True for child in elem_entry: existing_elem.append(child) - # Break out of the config_elems loop back to the elem_list loop so that section_found is reset to False - # and we can process the next section, if any. + # Break out of the config_elems loop back to the elem_list loop break - # If an existing section with a matching ID was not found, create that section and its tools. - if not section_found: - config_elems.append(elem_entry) + # If we reach this point, no section was found. Create one with contents. + config_elems.append(elem_entry) # This is not a section, but a tool or label. No need to search for matching sections, just add it. else: config_elems.append(elem_entry) From 009375163b4caaa39ca669fafd5580ebd805cb97 Mon Sep 17 00:00:00 2001 From: Dave Bouvier Date: Fri, 8 Jan 2021 09:32:36 -0500 Subject: [PATCH 5/6] Update comment. --- .../tool_shed/galaxy_install/tools/tool_panel_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py index 94fc336d23a..ff604fd6d19 100644 --- a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py @@ -61,10 +61,10 @@ class ToolPanelManager: for existing_elem in config_elems: # Compare the section ID for each one to the section ID for the tool being installed. if existing_elem.tag == 'section' and existing_elem.attrib.get('id', None) == elem_entry.attrib.get('id', None): - # We've found a section, set section_found to True so the subsequent if statement won't append it to the end. + # We've found a section, add the incoming tools to it. for child in elem_entry: existing_elem.append(child) - # Break out of the config_elems loop back to the elem_list loop + # Break out of the config_elems loop back to the elem_list loop. break # If we reach this point, no section was found. Create one with contents. config_elems.append(elem_entry) From b21f657761a1c6e303a4d255276532564438d1fd Mon Sep 17 00:00:00 2001 From: Dave B Date: Tue, 12 Jan 2021 14:13:16 -0500 Subject: [PATCH 6/6] Update lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py Co-authored-by: Marius van den Beek --- .../tool_shed/galaxy_install/tools/tool_panel_manager.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py index ff604fd6d19..3913134499b 100644 --- a/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py +++ b/lib/galaxy/tool_shed/galaxy_install/tools/tool_panel_manager.py @@ -67,7 +67,8 @@ class ToolPanelManager: # Break out of the config_elems loop back to the elem_list loop. break # If we reach this point, no section was found. Create one with contents. - config_elems.append(elem_entry) + else: + config_elems.append(elem_entry) # This is not a section, but a tool or label. No need to search for matching sections, just add it. else: config_elems.append(elem_entry)