Skip to content

Commit

Permalink
Add API endpoint to check for updates to installed repositories.
Browse files Browse the repository at this point in the history
  • Loading branch information
davebx committed Nov 17, 2015
1 parent 72e8f73 commit aff62e7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 45 deletions.
32 changes: 24 additions & 8 deletions lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py
Expand Up @@ -19,6 +19,7 @@
from tool_shed.util import hg_util
from tool_shed.util import workflow_util
from tool_shed.util import tool_util
from tool_shed.util import repository_util

import tool_shed.util.shed_util_common as suc

Expand Down Expand Up @@ -49,6 +50,21 @@ def __ensure_can_install_repos( self, trans ):
if not trans.user_is_admin():
raise exceptions.AdminRequiredException( 'You are not authorized to request the latest installable revision for a repository in this Galaxy instance.' )

@expose_api
def check_for_updates( self, trans, repository_id ):
'''
POST /api/tool_shed_repositories/check_for_updates/{id}
Check for updates to the specified repository, or all installed repositories.
:param key: the current Galaxy admin user's API key
The following parameters are included in the payload.
:param repository_id: the galaxy-side encoded repository ID
'''
message, status = repository_util.check_for_updates( trans.app, trans.install_model, repository_id )
return { 'status': status, 'message': message }
# Get the information about the repository to be updated from the payload.

@expose_api
def exported_workflows( self, trans, id, **kwd ):
"""
Expand Down Expand Up @@ -378,20 +394,20 @@ def repair_repository_revision( self, trans, payload, **kwd ):

def __parse_repository_from_payload( self, payload, include_changeset=False ):
# 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:
tool_shed_url = payload.get( 'tool_shed_url', None )
name = payload.get( 'name', None )
owner = payload.get( 'owner', None )
if tool_shed_url is None:
raise exceptions.RequestParameterMissingException( "Missing required parameter 'tool_shed_url'." )
name = payload.get( 'name', '' )
if not name:
if name is None:
raise exceptions.RequestParameterMissingException( "Missing required parameter 'name'." )
owner = payload.get( 'owner', '' )
if not owner:
if owner is None:
raise exceptions.RequestParameterMissingException( "Missing required parameter 'owner'." )
if not include_changeset:
return tool_shed_url, name, owner

changeset_revision = payload.get( 'changeset_revision', '' )
if not changeset_revision:
changeset_revision = payload.get( 'changeset_revision', None )
if changeset_revision is None:
raise HTTPBadRequest( detail="Missing required parameter 'changeset_revision'." )

return tool_shed_url, name, owner, changeset_revision
Expand Down
6 changes: 6 additions & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Expand Up @@ -567,6 +567,12 @@ def populate_api_routes( webapp, app ):
new={ 'install_repository_revision': 'POST' },
parent_resources=dict( member_name='tool_shed_repository', collection_name='tool_shed_repositories' ) )

webapp.mapper.connect( 'repository_update',
'/api/tool_shed_repositories/check_for_updates/{repository_id}',
controller='tool_shed_repositories',
action='check_for_updates',
repository_id=None )

# ==== Trace/Metrics Logger
# Connect logger from app
if app.trace_logger:
Expand Down
37 changes: 2 additions & 35 deletions lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
Expand Up @@ -2006,41 +2006,8 @@ def update_to_changeset_revision( self, trans, **kwd ):

@web.expose
@web.require_admin
def update_tool_shed_status_for_installed_repository( self, trans, all_installed_repositories=False, **kwd ):
message = escape( kwd.get( 'message', '' ) )
status = kwd.get( 'status', 'done' )
if all_installed_repositories:
success_count = 0
repository_names_not_updated = []
updated_count = 0
for repository in trans.install_model.context.query( trans.install_model.ToolShedRepository ) \
.filter( trans.install_model.ToolShedRepository.table.c.deleted == false() ):
ok, updated = \
repository_util.check_or_update_tool_shed_status_for_installed_repository( trans.app, repository )
if ok:
success_count += 1
else:
repository_names_not_updated.append( '<b>%s</b>' % escape( str( repository.name ) ) )
if updated:
updated_count += 1
message = "Checked the status in the tool shed for %d repositories. " % success_count
message += "Updated the tool shed status for %d repositories. " % updated_count
if repository_names_not_updated:
message += "Unable to retrieve status from the tool shed for the following repositories:\n"
message += ", ".join( repository_names_not_updated )
else:
repository_id = kwd.get( 'id', None )
repository = suc.get_tool_shed_repository_by_id( trans.app, repository_id )
ok, updated = \
repository_util.check_or_update_tool_shed_status_for_installed_repository( trans.app, repository )
if ok:
if updated:
message = "The tool shed status for repository <b>%s</b> has been updated." % escape( str( repository.name ) )
else:
message = "The status has not changed in the tool shed for repository <b>%s</b>." % escape( str( repository.name ) )
else:
message = "Unable to retrieve status from the tool shed for repository <b>%s</b>." % escape( str( repository.name ) )
status = 'error'
def update_tool_shed_status_for_installed_repository( self, trans, **kwd ):
message, status = repository_util.check_for_updates( trans.app, trans.install_model, kwd.get( 'id', None ) )
return trans.response.send_redirect( web.url_for( controller='admin_toolshed',
action='browse_repositories',
message=message,
Expand Down
37 changes: 37 additions & 0 deletions lib/tool_shed/util/repository_util.py
Expand Up @@ -408,6 +408,43 @@ def handle_role_associations( app, role, repository, **kwd ):
return associations_dict


def check_for_updates( app, model, repository_id=None ):
message = ''
status = 'ok'
if repository_id is None:
success_count = 0
repository_names_not_updated = []
updated_count = 0
for repository in model.context.query( model.ToolShedRepository ) \
.filter( model.ToolShedRepository.table.c.deleted == false() ):
ok, updated = \
check_or_update_tool_shed_status_for_installed_repository( app, repository )
if ok:
success_count += 1
else:
repository_names_not_updated.append( '<b>%s</b>' % escape( str( repository.name ) ) )
if updated:
updated_count += 1
message = "Checked the status in the tool shed for %d repositories. " % success_count
message += "Updated the tool shed status for %d repositories. " % updated_count
if repository_names_not_updated:
message += "Unable to retrieve status from the tool shed for the following repositories:\n"
message += ", ".join( repository_names_not_updated )
else:
repository = suc.get_tool_shed_repository_by_id( app, repository_id )
ok, updated = \
check_or_update_tool_shed_status_for_installed_repository( app, repository )
if ok:
if updated:
message = "The tool shed status for repository <b>%s</b> has been updated." % escape( str( repository.name ) )
else:
message = "The status has not changed in the tool shed for repository <b>%s</b>." % escape( str( repository.name ) )
else:
message = "Unable to retrieve status from the tool shed for repository <b>%s</b>." % escape( str( repository.name ) )
status = 'error'
return message, status


def validate_repository_name( app, name, user ):
"""
Validate whether the given name qualifies as a new TS repo name.
Expand Down
4 changes: 2 additions & 2 deletions lib/tool_shed/util/shed_util_common.py
Expand Up @@ -414,8 +414,8 @@ def get_repo_info_tuple_contents( repo_info_tuple ):

def get_repositories_by_category( app, category_id ):
sa_session = app.model.context.current
repositories = sa_session.query( app.model.Category ).get( category_id )
return [ repo.repository.to_dict() for repo in foo.repositories ]
resultset = sa_session.query( app.model.Category ).get( category_id )
return [ repo.repository.to_dict() for repo in resultset.repositories ]


def get_repository_and_repository_dependencies_from_repo_info_dict( app, repo_info_dict ):
Expand Down

0 comments on commit aff62e7

Please sign in to comment.