From b741ce0d49ab2db80f668e090a5d6a7336a10405 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sat, 23 Feb 2013 14:09:53 -0600 Subject: [PATCH] Extend tool config macro engine so that macros may be rendered inside other macros. --- lib/galaxy/tools/__init__.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index a58d8f92360..db32ab835bc 100755 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -714,16 +714,24 @@ class ToolBox( object ): return tree tool_dir = os.path.dirname(config_file) macros = self._load_macros(macros_el, tool_dir) - # HACK for elementtree, newer implementations (etree/lxml) won't - # require this parent_map data structure but elementtree does not - # track parents or recongnize .find('..'). - parent_map = dict((c, p) for p in tree.getiterator() for c in p) - for expand_el in root.findall('.//expand'): - macro_name = expand_el.get('macro') - macro_def = macros[macro_name] - self._xml_replace(expand_el, macro_def, parent_map) + + self._expand_macros([root], macros) return tree + def _expand_macros(self, elements, macros): + for element in elements: + # HACK for elementtree, newer implementations (etree/lxml) won't + # require this parent_map data structure but elementtree does not + # track parents or recongnize .find('..'). + parent_map = dict((c, p) for p in element.getiterator() for c in p) + for expand_el in element.findall('.//expand'): + macro_name = expand_el.get('macro') + macro_def = macros[macro_name] + + # Recursively expand contained macros. + self._expand_macros(macro_def, macros) + self._xml_replace(expand_el, macro_def, parent_map) + def _load_macros(self, macros_el, tool_dir): macros = {} # Import macros from external files. @@ -785,6 +793,7 @@ class ToolBox( object ): parent_el.insert(current_index, deepcopy(target)) parent_el.remove(query) + class ToolSection( object ): """ A group of tools with similar type/purpose that will be displayed as a