From 92e4dbfcdd5b222dce851b60a22eea540b01a423 Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Tue, 6 Aug 2013 11:04:54 -0400 Subject: [PATCH] Keep track of category associations when exporting repositories from the tool shed. --- lib/tool_shed/util/export_util.py | 6 ++++++ lib/tool_shed/util/xml_util.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/tool_shed/util/export_util.py b/lib/tool_shed/util/export_util.py index 75a1731d5bb..76c1c30ca1b 100644 --- a/lib/tool_shed/util/export_util.py +++ b/lib/tool_shed/util/export_util.py @@ -246,6 +246,12 @@ def get_repository_attributes_and_sub_elements( repository, archive_name ): sub_elements[ 'description' ] = str( repository.description ) sub_elements[ 'long_description' ] = str( repository.long_description ) sub_elements[ 'archive' ] = archive_name + # Keep track of Category associations. + categories = [] + for rca in repository.categories: + category = rca.category + categories.append( ( 'category', str( category.name ) ) ) + sub_elements[ 'categories' ] = categories return attributes, sub_elements def get_repository_ids( trans, repo_info_dicts ): diff --git a/lib/tool_shed/util/xml_util.py b/lib/tool_shed/util/xml_util.py index 55aad4ad0ae..4ee96fb424f 100644 --- a/lib/tool_shed/util/xml_util.py +++ b/lib/tool_shed/util/xml_util.py @@ -62,7 +62,18 @@ def create_element( tag, attributes=None, sub_elements=None ): # Don't include fields that are blank. if v: sub_elem = XmlET.SubElement( elem, k ) - sub_elem.text = v + if isinstance( v, list ): + # If the sub_elem is a list, then it must be a list of tuples where the first item is the tag and the second item is the text value. + for v_tuple in v: + if len( v_tuple ) == 2: + v_tag = v_tuple[ 0 ] + v_text = v_tuple[ 1 ] + # Don't include fields that are blank. + if v_text: + v_elem = XmlET.SubElement( sub_elem, v_tag ) + v_elem.text = v_text + else: + sub_elem.text = v return elem return None