From aff62e76c8c8a862166c7e0ac899b2c1a79fea86 Mon Sep 17 00:00:00 2001 From: Dave B Date: Tue, 17 Nov 2015 16:54:51 -0500 Subject: [PATCH] Add API endpoint to check for updates to installed repositories. --- .../galaxy/api/tool_shed_repositories.py | 32 ++++++++++++---- lib/galaxy/webapps/galaxy/buildapp.py | 6 +++ .../galaxy/controllers/admin_toolshed.py | 37 +------------------ lib/tool_shed/util/repository_util.py | 37 +++++++++++++++++++ lib/tool_shed/util/shed_util_common.py | 4 +- 5 files changed, 71 insertions(+), 45 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py index d36275650916..656066295536 100644 --- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py +++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py @@ -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 @@ -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 ): """ @@ -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 diff --git a/lib/galaxy/webapps/galaxy/buildapp.py b/lib/galaxy/webapps/galaxy/buildapp.py index b922a30fa29a..2af0164a10ef 100644 --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -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: diff --git a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py index 26fc1d10379a..a8fb413d4d83 100644 --- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py @@ -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( '%s' % 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 %s has been updated." % escape( str( repository.name ) ) - else: - message = "The status has not changed in the tool shed for repository %s." % escape( str( repository.name ) ) - else: - message = "Unable to retrieve status from the tool shed for repository %s." % 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, diff --git a/lib/tool_shed/util/repository_util.py b/lib/tool_shed/util/repository_util.py index ac35e838402a..035acc46d7bc 100644 --- a/lib/tool_shed/util/repository_util.py +++ b/lib/tool_shed/util/repository_util.py @@ -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( '%s' % 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 %s has been updated." % escape( str( repository.name ) ) + else: + message = "The status has not changed in the tool shed for repository %s." % escape( str( repository.name ) ) + else: + message = "Unable to retrieve status from the tool shed for repository %s." % 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. diff --git a/lib/tool_shed/util/shed_util_common.py b/lib/tool_shed/util/shed_util_common.py index 570be4d696fb..75986141a6cb 100644 --- a/lib/tool_shed/util/shed_util_common.py +++ b/lib/tool_shed/util/shed_util_common.py @@ -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 ):