1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/9a1415f8108f/ Changeset: 9a1415f8108f User: greg Date: 2014-05-15 00:13:33 Summary: Enhance the galaxy API for the Tool Shed to retrieve the latest installable revision from the Tool Shed from an installed repository, specifying a name and owner. Enhance the ~/scripts/api/install_tool_shed_repositories.py script to allow the changeset_revision to be optional, and if not specified, the latest installable revision will be installed for the repository specified by the name and owner. Affected #: 3 files diff -r 22ec0ac1ebcd1cc5ae5fda4ec70723043e8d5c5f -r 9a1415f8108f6283181c7a5b564118920359decc lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -66,6 +66,50 @@ exported_workflows.append( display_dict ) return exported_workflows + @web.expose_api + def get_latest_installable_revision( self, trans, payload, **kwd ): + """ + POST /api/tool_shed_repositories/get_latest_installable_revision + Get the latest installable revision of a specified repository from a specified Tool Shed. + + :param key: the current Galaxy admin user's API key + + The following parameters are included in the payload. + :param tool_shed_url (required): the base URL of the Tool Shed from which to retrieve the Repository revision. + :param name (required): the name of the Repository + :param owner (required): the owner of the Repository + """ + # Get the information about the repository to be installed from the payload. + tool_shed_url = payload.get( 'tool_shed_url', '' ) + if not tool_shed_url: + raise HTTPBadRequest( detail="Missing required parameter 'tool_shed_url'." ) + name = payload.get( 'name', '' ) + if not name: + raise HTTPBadRequest( detail="Missing required parameter 'name'." ) + owner = payload.get( 'owner', '' ) + if not owner: + raise HTTPBadRequest( detail="Missing required parameter 'owner'." ) + # Make sure the current user's API key proves he is an admin user in this Galaxy instance. + if not trans.user_is_admin(): + raise HTTPForbidden( detail='You are not authorized to request the latest installable revision for a repository in this Galaxy instance.' ) + params = '?name=%s&owner=%s' % ( name, owner ) + url = common_util.url_join( tool_shed_url, + 'api/repositories/get_ordered_installable_revisions%s' % params ) + try: + raw_text = common_util.tool_shed_get( trans.app, tool_shed_url, url ) + except Exception, e: + message = "Error attempting to retrieve the latest installable revision from tool shed %s for repository %s owned by %s: %s" % \ + ( str( tool_shed_url ), str( name ), str( owner ), str( e ) ) + log.debug( message ) + return dict( status='error', error=message ) + if raw_text: + # If successful, the response from get_ordered_installable_revisions will be a list of + # changeset_revision hash strings. + changeset_revisions = json.from_json_string( raw_text ) + if len( changeset_revisions ) >= 1: + return changeset_revisions[ -1 ] + return suc.INITIAL_CHANGELOG_HASH + def __get_value_mapper( self, trans, tool_shed_repository ): value_mapper={ 'id' : trans.security.encode_id( tool_shed_repository.id ), 'error_message' : tool_shed_repository.error_message or '' } diff -r 22ec0ac1ebcd1cc5ae5fda4ec70723043e8d5c5f -r 9a1415f8108f6283181c7a5b564118920359decc lib/galaxy/webapps/galaxy/buildapp.py --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -321,7 +321,8 @@ 'exported_workflows' : 'GET', 'import_workflow' : 'POST', 'import_workflows' : 'POST' }, - collection={ 'reset_metadata_on_installed_repositories' : 'POST' }, + collection={ 'get_latest_installable_revision' : 'POST', + 'reset_metadata_on_installed_repositories' : 'POST' }, controller='tool_shed_repositories', name_prefix='tool_shed_repository_', path_prefix='/api', diff -r 22ec0ac1ebcd1cc5ae5fda4ec70723043e8d5c5f -r 9a1415f8108f6283181c7a5b564118920359decc scripts/api/install_tool_shed_repositories.py --- a/scripts/api/install_tool_shed_repositories.py +++ b/scripts/api/install_tool_shed_repositories.py @@ -1,8 +1,12 @@ #!/usr/bin/env python """ -Install a specified repository revision from a specified tool shed into Galaxy. This example demonstrates installation of a repository that contains -valid tools, loading them into a section of the Galaxy tool panel or creating a new tool panel section. -You can choose if tool dependencies or repository dependencies should be installed, use --repository-deps or --tool-deps. +If a repository name, owner and revision are specified,install the revision from a specified tool shed into Galaxy. +Specifying a revision is optional, if it is no specified, the latest installable revision will automatically be installed. +However, the name and owner are required. + +This example demonstrates installation of a repository that contains valid tools, loading them into a section of the +Galaxy tool panel or creating a new tool panel section. You can choose if tool dependencies or repository dependencies +should be installed, use --repository-deps or --tool-deps. This example requires a tool panel config file (e.g., tool_conf.xml, shed_tool_conf.xml, etc) to contain a tool panel section like the following: @@ -10,7 +14,7 @@ </section> Here is a working example of how to use this script to install a repository from the test tool shed. -./install_tool_shed_repositories.py --api <api key> --local <galaxy base url> --url http://testtoolshed.g2.bx.psu.edu --name gregs_filter --owner greg --revision f28d5018f9cb --tool-deps +./install_tool_shed_repositories.py --api <api key> --local <galaxy base url> --url http://testtoolshed.g2.bx.psu.edu --name gregs_filter --owner greg --tool-deps """ import os @@ -25,7 +29,20 @@ data[ 'tool_shed_url' ] = options.tool_shed_url data[ 'name' ] = options.name data[ 'owner' ] = options.owner - data[ 'changeset_revision' ] = options.changeset_revision + if options.changeset_revision: + data[ 'changeset_revision' ] = options.changeset_revision + else: + # If the changeset_revision is not specified, default to the latest installable revision. + revision_data = {} + revision_data[ 'tool_shed_url' ] = options.tool_shed_url.rstrip( '/' ) + revision_data[ 'name' ] = options.name + revision_data[ 'owner' ] = options.owner + revision_url = '%s%s' % ( options.local_url.rstrip( '/' ), '/api/tool_shed_repositories/get_latest_installable_revision' ) + latest_installable_revision = submit( options.api, + revision_url, + revision_data, + return_formatted=False ) + data[ 'changeset_revision' ] = latest_installable_revision if options.tool_panel_section_id: data[ 'tool_panel_section_id' ] = options.tool_panel_section_id elif options.new_tool_panel_section_label: @@ -34,7 +51,7 @@ data[ 'install_repository_dependencies' ] = options.install_repository_dependencies if options.install_tool_dependencies: data[ 'install_tool_dependencies' ] = options.install_tool_dependencies - submit( options.api, '%s%s' % ( options.local_url.strip( '/' ), '/api/tool_shed_repositories/new/install_repository_revision' ), data ) + submit( options.api, '%s%s' % ( options.local_url.rstrip( '/' ), '/api/tool_shed_repositories/new/install_repository_revision' ), data ) if __name__ == '__main__': parser = argparse.ArgumentParser( description='Installation of tool shed repositories via the Galaxy API.' ) @@ -43,7 +60,7 @@ parser.add_argument( "-l", "--local", dest="local_url", required=True, help="URL of the galaxy instance." ) parser.add_argument( "-n", "--name", required=True, help="Repository name." ) parser.add_argument( "-o", "--owner", required=True, help="Repository owner." ) - parser.add_argument( "-r", "--revision", dest="changeset_revision", required=True, help="Repository owner." ) + parser.add_argument( "-r", "--revision", dest="changeset_revision", help="Repository revision." ) parser.add_argument( "--panel-section-id", dest="tool_panel_section_id", help="Tool panel section id if you want to add your repository to an existing tool section." ) parser.add_argument( "--panel-section-name", dest="new_tool_panel_section_label", help="New tool panel section label. If specified a new tool section will be created." ) parser.add_argument( "--repository-deps", dest="install_repository_dependencies", action="store_true", default=False, help="Install repository dependencies. [False]") 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.