Skip to content

Commit

Permalink
Enhance the galaxy API for the Tool Shed to retrieve the latest insta…
Browse files Browse the repository at this point in the history
…llable 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.
  • Loading branch information
gregvonkuster committed May 14, 2014
1 parent d18dee9 commit 2d5c37a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
44 changes: 44 additions & 0 deletions lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py
Expand Up @@ -66,6 +66,50 @@ def exported_workflows( self, trans, id, **kwd ):
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 '' }
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/webapps/galaxy/buildapp.py
Expand Up @@ -321,7 +321,8 @@ def app_factory( global_conf, **kwargs ):
'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',
Expand Down
31 changes: 24 additions & 7 deletions scripts/api/install_tool_shed_repositories.py
@@ -1,16 +1,20 @@
#!/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:
<section id="from_test_tool_shed" name="From Test Tool Shed" version="">
</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
Expand All @@ -25,7 +29,20 @@ def main( options ):
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:
Expand All @@ -34,7 +51,7 @@ def main( options ):
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.' )
Expand All @@ -43,7 +60,7 @@ def main( options ):
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]")
Expand Down

0 comments on commit 2d5c37a

Please sign in to comment.