From 31d457cfc5149ca4c99f3fb7989cc644dd15fa60 Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Mon, 5 Aug 2013 16:45:16 -0400 Subject: [PATCH] Include a file name export_info.xml to repository archives for repositories exported from the tool shed. --- lib/tool_shed/util/export_util.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/tool_shed/util/export_util.py b/lib/tool_shed/util/export_util.py index 036d4e10049..75a1731d5bb 100644 --- a/lib/tool_shed/util/export_util.py +++ b/lib/tool_shed/util/export_util.py @@ -4,6 +4,8 @@ import shutil import tarfile import tempfile import threading +from time import gmtime +from time import strftime import tool_shed.util.shed_util_common as suc from galaxy import eggs from galaxy import web @@ -97,9 +99,14 @@ def export_repository( trans, tool_shed_url, repository_id, repository_name, cha elem = xml_util.create_element( 'repository', attributes=attributes, sub_elements=sub_elements ) exported_repository_registry.exported_repository_elems.append( elem ) shutil.rmtree( work_dir ) + # Keep information about the export in a file name export_info.xml in the archive. + sub_elements = generate_export_elem( tool_shed_url, repository, changeset_revision, export_repository_dependencies, api ) + export_elem = xml_util.create_element( 'export_info', attributes=None, sub_elements=sub_elements ) + tmp_export_info = xml_util.create_and_write_tmp_file( export_elem, use_indent=True ) + repositories_archive.add( tmp_export_info, arcname='export_info.xml' ) # Write the manifest, which must preserve the order in which the repositories should be imported. - tmp_xml_file = xml_util.create_and_write_tmp_file( exported_repository_registry.exported_repository_elems, use_indent=True ) - repositories_archive.add( tmp_xml_file, arcname='manifest.xml' ) + tmp_manifest = xml_util.create_and_write_tmp_file( exported_repository_registry.exported_repository_elems, use_indent=True ) + repositories_archive.add( tmp_manifest, arcname='manifest.xml' ) except Exception, e: log.exception( str( e ) ) finally: @@ -161,6 +168,17 @@ def generate_repository_archive_filename( tool_shed_url, name, owner, changeset_ repositories_archive_filename = os.path.join( tmp_archive_dir, repositories_archive_filename ) return repositories_archive_filename +def generate_export_elem( tool_shed_url, repository, changeset_revision, export_repository_dependencies, api ): + sub_elements = odict() + sub_elements[ 'export_time' ] = strftime( '%a, %d %b %Y %H:%M:%S +0000', gmtime() ) + sub_elements[ 'tool_shed' ] = str( tool_shed_url.rstrip( '/' ) ) + sub_elements[ 'repository_name' ] = str( repository.name ) + sub_elements[ 'repository_owner' ] = str( repository.user.username ) + sub_elements[ 'changeset_revision' ] = str( changeset_revision ) + sub_elements[ 'export_repository_dependencies' ] = str( export_repository_dependencies ) + sub_elements[ 'exported_via_api' ] = str( api ) + return sub_elements + def get_components_from_repo_info_dict( trans, repo_info_dict ): """ Return the repository and the associated latest installable changeset_revision (including updates) for the repository defined by the received