commit/galaxy-central: 2 new changesets

2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/a243d2dbca9d/ Changeset: a243d2dbca9d Branch: next-stable User: greg Date: 2013-06-03 21:40:37 Summary: Fix for rendering xml elements that were not loaded using normal parsing methods. Affected #: 2 files diff -r 09d45fa9a84c1a91e7b14b94186bd8128883ddc4 -r a243d2dbca9d88724d03848a4136d9ae88d0b174 lib/tool_shed/util/shed_util_common.py --- a/lib/tool_shed/util/shed_util_common.py +++ b/lib/tool_shed/util/shed_util_common.py @@ -193,7 +193,7 @@ os.write( fd, '<?xml version="1.0"?>\n' ) os.write( fd, '<toolbox tool_path="%s">\n' % str( tool_path ) ) for elem in config_elems: - os.write( fd, '%s' % xml_util.xml_to_string( elem ) ) + os.write( fd, '%s' % xml_util.xml_to_string( elem, use_indent=True ) ) os.write( fd, '</toolbox>\n' ) os.close( fd ) shutil.move( filename, os.path.abspath( config_filename ) ) diff -r 09d45fa9a84c1a91e7b14b94186bd8128883ddc4 -r a243d2dbca9d88724d03848a4136d9ae88d0b174 lib/tool_shed/util/xml_util.py --- a/lib/tool_shed/util/xml_util.py +++ b/lib/tool_shed/util/xml_util.py @@ -41,6 +41,28 @@ fh.close() return tmp_filename +def indent( elem, level=0 ): + """ + Prints an XML tree with each node indented according to its depth. This method is used to print the shed tool config (e.g., shed_tool_conf.xml + from the in-memory list of config_elems because each config_elem in the list may be a hierarchical structure that was not created using the + parse_xml() method below, and so will not be properly written with xml.etree.ElementTree.tostring() without manually indenting the tree first. + """ + i = "\n" + level * " " + if len( elem ): + if not elem.text or not elem.text.strip(): + elem.text = i + " " + if not elem.tail or not elem.tail.strip(): + elem.tail = i + for child in elem: + indent( child, level+1 ) + if not child.tail or not child.tail.strip(): + child.tail = i + if not elem.tail or not elem.tail.strip(): + elem.tail = i + else: + if level and ( not elem.tail or not elem.tail.strip() ): + elem.tail = i + def parse_xml( file_name ): """Returns a parsed xml tree with comments intact.""" error_message = '' @@ -64,9 +86,15 @@ fobj.close() return tree, error_message -def xml_to_string( elem, encoding='utf-8' ): - if using_python_27: - xml_str = '%s\n' % xml.etree.ElementTree.tostring( elem, encoding=encoding, method="xml" ) +def xml_to_string( elem, encoding='utf-8', use_indent=False ): + if elem: + if use_indent: + # We were called from suc.config_elems_to_xml_file(), so set the level to 1 since level 0 is the <toolbox> tag set. + indent( elem, level=1 ) + if using_python_27: + xml_str = '%s\n' % xml.etree.ElementTree.tostring( elem, encoding=encoding, method="xml" ) + else: + xml_str = '%s\n' % xml.etree.ElementTree.tostring( elem, encoding=encoding ) else: - xml_str = '%s\n' % xml.etree.ElementTree.tostring( elem, encoding=encoding ) + xml_str = '' return xml_str https://bitbucket.org/galaxy/galaxy-central/commits/8cbb23ed305e/ Changeset: 8cbb23ed305e User: greg Date: 2013-06-03 21:40:58 Summary: Merged from next-stable Affected #: 2 files diff -r 75bea1afc2e3e3a49c95a3540a27be165766aaac -r 8cbb23ed305e6803da733eb7be74bab779ee9ea4 lib/tool_shed/util/shed_util_common.py --- a/lib/tool_shed/util/shed_util_common.py +++ b/lib/tool_shed/util/shed_util_common.py @@ -193,7 +193,7 @@ os.write( fd, '<?xml version="1.0"?>\n' ) os.write( fd, '<toolbox tool_path="%s">\n' % str( tool_path ) ) for elem in config_elems: - os.write( fd, '%s' % xml_util.xml_to_string( elem ) ) + os.write( fd, '%s' % xml_util.xml_to_string( elem, use_indent=True ) ) os.write( fd, '</toolbox>\n' ) os.close( fd ) shutil.move( filename, os.path.abspath( config_filename ) ) diff -r 75bea1afc2e3e3a49c95a3540a27be165766aaac -r 8cbb23ed305e6803da733eb7be74bab779ee9ea4 lib/tool_shed/util/xml_util.py --- a/lib/tool_shed/util/xml_util.py +++ b/lib/tool_shed/util/xml_util.py @@ -41,6 +41,28 @@ fh.close() return tmp_filename +def indent( elem, level=0 ): + """ + Prints an XML tree with each node indented according to its depth. This method is used to print the shed tool config (e.g., shed_tool_conf.xml + from the in-memory list of config_elems because each config_elem in the list may be a hierarchical structure that was not created using the + parse_xml() method below, and so will not be properly written with xml.etree.ElementTree.tostring() without manually indenting the tree first. + """ + i = "\n" + level * " " + if len( elem ): + if not elem.text or not elem.text.strip(): + elem.text = i + " " + if not elem.tail or not elem.tail.strip(): + elem.tail = i + for child in elem: + indent( child, level+1 ) + if not child.tail or not child.tail.strip(): + child.tail = i + if not elem.tail or not elem.tail.strip(): + elem.tail = i + else: + if level and ( not elem.tail or not elem.tail.strip() ): + elem.tail = i + def parse_xml( file_name ): """Returns a parsed xml tree with comments intact.""" error_message = '' @@ -64,9 +86,15 @@ fobj.close() return tree, error_message -def xml_to_string( elem, encoding='utf-8' ): - if using_python_27: - xml_str = '%s\n' % xml.etree.ElementTree.tostring( elem, encoding=encoding, method="xml" ) +def xml_to_string( elem, encoding='utf-8', use_indent=False ): + if elem: + if use_indent: + # We were called from suc.config_elems_to_xml_file(), so set the level to 1 since level 0 is the <toolbox> tag set. + indent( elem, level=1 ) + if using_python_27: + xml_str = '%s\n' % xml.etree.ElementTree.tostring( elem, encoding=encoding, method="xml" ) + else: + xml_str = '%s\n' % xml.etree.ElementTree.tostring( elem, encoding=encoding ) else: - xml_str = '%s\n' % xml.etree.ElementTree.tostring( elem, encoding=encoding ) + xml_str = '' return xml_str Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org