From 4d781de114f021bf25068d03c5b58bd21f45f16d Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Tue, 21 May 2013 12:26:55 -0400 Subject: [PATCH] Fixes for complext repository dependency definitions that do not include a changeset_revision attribute. A fix for indenting the updates XML file is also included. --- .../webapps/tool_shed/controllers/upload.py | 12 ++++++------ lib/tool_shed/util/commit_util.py | 15 ++++++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/galaxy/webapps/tool_shed/controllers/upload.py b/lib/galaxy/webapps/tool_shed/controllers/upload.py index c273f2fcd3b..69823cf79b9 100644 --- a/lib/galaxy/webapps/tool_shed/controllers/upload.py +++ b/lib/galaxy/webapps/tool_shed/controllers/upload.py @@ -131,7 +131,7 @@ class UploadController( BaseUIController ): # Inspect the contents of the file to see if changeset_revision values are missing and if so, set them appropriately. altered, root = commit_util.handle_repository_dependencies_definition( trans, uploaded_file_name ) if altered: - tmp_filename = commit_util.create_and_write_tmp_file( util.xml_to_string( root, pretty=True ) ) + tmp_filename = commit_util.create_and_write_tmp_file( root ) shutil.move( tmp_filename, full_path ) else: shutil.move( uploaded_file_name, full_path ) @@ -140,7 +140,7 @@ class UploadController( BaseUIController ): # are missing and if so, set them appropriately. altered, root = commit_util.handle_tool_dependencies_definition( trans, uploaded_file_name ) if altered: - tmp_filename = commit_util.create_and_write_tmp_file( util.xml_to_string( root, pretty=True ) ) + tmp_filename = commit_util.create_and_write_tmp_file( root ) shutil.move( tmp_filename, full_path ) else: shutil.move( uploaded_file_name, full_path ) @@ -268,13 +268,13 @@ class UploadController( BaseUIController ): # Inspect the contents of the file to see if changeset_revision values are missing and if so, set them appropriately. altered, root = commit_util.handle_repository_dependencies_definition( trans, uploaded_file_name ) if altered: - tmp_filename = commit_util.create_and_write_tmp_file( util.xml_to_string( root, pretty=True ) ) + tmp_filename = commit_util.create_and_write_tmp_file( root ) shutil.move( tmp_filename, uploaded_file_name ) elif os.path.split( uploaded_file_name )[ -1 ] == 'tool_dependencies.xml': # Inspect the contents of the file to see if changeset_revision values are missing and if so, set them appropriately. altered, root = commit_util.handle_tool_dependencies_definition( trans, uploaded_file_name ) if altered: - tmp_filename = commit_util.create_and_write_tmp_file( util.xml_to_string( root, pretty=True ) ) + tmp_filename = commit_util.create_and_write_tmp_file( root ) shutil.move( tmp_filename, uploaded_file_name ) if ok: repo_path = os.path.join( full_path, relative_path ) @@ -330,13 +330,13 @@ class UploadController( BaseUIController ): # Inspect the contents of the file to see if changeset_revision values are missing and if so, set them appropriately. altered, root = commit_util.handle_repository_dependencies_definition( trans, uploaded_file_name ) if altered: - tmp_filename = commit_util.create_and_write_tmp_file( util.xml_to_string( root, pretty=True ) ) + tmp_filename = commit_util.create_and_write_tmp_file( root ) shutil.move( tmp_filename, uploaded_file_name ) elif os.path.split( uploaded_file_name )[ -1 ] == 'tool_dependencies.xml': # Inspect the contents of the file to see if changeset_revision values are missing and if so, set them appropriately. altered, root = commit_util.handle_tool_dependencies_definition( trans, uploaded_file_name ) if altered: - tmp_filename = commit_util.create_and_write_tmp_file( util.xml_to_string( root, pretty=True ) ) + tmp_filename = commit_util.create_and_write_tmp_file( root ) shutil.move( tmp_filename, uploaded_file_name ) return commit_util.handle_directory_changes( trans, repository, diff --git a/lib/tool_shed/util/commit_util.py b/lib/tool_shed/util/commit_util.py index 29bb3a33c7b..58ed1e40ad1 100644 --- a/lib/tool_shed/util/commit_util.py +++ b/lib/tool_shed/util/commit_util.py @@ -1,5 +1,6 @@ import logging import os +import pkg_resources import shutil import tempfile from galaxy import util @@ -9,11 +10,15 @@ import tool_shed.util.shed_util_common as suc from tool_shed.util import tool_util from galaxy import eggs + eggs.require( 'mercurial' ) from mercurial import commands from mercurial import hg from mercurial import ui +pkg_resources.require( 'elementtree' ) +from elementtree.ElementTree import tostring + log = logging.getLogger( __name__ ) UNDESIRABLE_DIRS = [ '.hg', '.svn', '.git', '.cvs' ] @@ -57,13 +62,13 @@ def check_file_content_for_html_and_images( file_path ): message = 'The file "%s" contains image content.\n' % str( file_path ) return message -def create_and_write_tmp_file( text ): +def create_and_write_tmp_file( root ): fh = tempfile.NamedTemporaryFile( 'wb' ) tmp_filename = fh.name fh.close() fh = open( tmp_filename, 'wb' ) fh.write( '\n' ) - fh.write( text ) + fh.write( tostring( root, 'utf-8' ) ) fh.close() return tmp_filename @@ -255,7 +260,6 @@ def handle_tool_dependencies_definition( trans, tool_dependencies_config ): package_altered = True if not altered: altered = True - elif package_elem.tag == 'install': # for actions_index, actions_elem in enumerate( package_elem ): @@ -277,8 +281,9 @@ def handle_tool_dependencies_definition( trans, tool_dependencies_config ): if package_altered: actions_elem[ action_index ] = action_elem if package_altered: - root_elem[ actions_index ] = actions_elem - + package_elem[ actions_index ] = actions_elem + if package_altered: + root_elem[ package_index ] = package_elem if package_altered: root[ root_index ] = root_elem return altered, root