Skip to content

Commit

Permalink
Add uninstall_repository to ToolShedRepositoriesController
Browse files Browse the repository at this point in the history
And connect routes. It is now possible to POST to
api/tool_shed_repositories to trigger a Repository installation and to
DELETE to api/tool_shed_repositories to uninstall a repository. In
addition one can also DELETE to
api/tool_shed_repositories/<repository_id>, which will uninstall the
repository with repository_id.
  • Loading branch information
mvdbeek committed Jun 27, 2017
1 parent b29f235 commit 67c6686
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from galaxy.web.base.controller import BaseAPIController

from tool_shed.galaxy_install.install_manager import InstallRepositoryManager
from tool_shed.galaxy_install.installed_repository_manager import InstalledRepositoryManager
from tool_shed.galaxy_install.metadata.installed_repository_metadata_manager import InstalledRepositoryMetadataManager
from tool_shed.galaxy_install.repair_repository_manager import RepairRepositoryManager
from tool_shed.util import common_util
Expand Down Expand Up @@ -616,6 +617,46 @@ def install_repository_revisions( self, trans, payload, **kwd ):
all_installed_tool_shed_repositories.extend( installed_tool_shed_repositories )
return all_installed_tool_shed_repositories

@expose_api
def uninstall_repository(self, trans, id=None, **kwd):
"""
DELETE /api/tool_shed_repositories/id
DELETE /api/tool_shed_repositories/
:param id: encoded repository id. Either id or name, owner, changeset_revision and tool_shed_url need to be supplied
:param kwd: 'remove_from_disk' : Remove repository from disk or deactivate repository.
Defaults to `True` (= remove repository from disk).
'name' : Repository name
'owner' : Repository owner
'changeset_revision': Changeset revision to uninstall
'tool_shed_url' : Tool Shed URL
"""
if id:
try:
repository = repository_util.get_tool_shed_repository_by_id(self.app, id)
except ValueError:
raise HTTPBadRequest(detail="No repository with id '%s' found" % id)
else:
tsr_arguments = ['name', 'owner', 'changeset_revision', 'tool_shed_url']
try:
tsr_arguments = {key: kwd[key] for key in tsr_arguments}
except KeyError as e:
raise HTTPBadRequest(detail="Missing required parameter '%s'" % e.args[0])
repository = repository_util.get_installed_repository(app=self.app,
tool_shed=tsr_arguments['tool_shed_url'],
name=tsr_arguments['name'],
owner=tsr_arguments['owner'],
changeset_revision=tsr_arguments['changeset_revision'])
if not repository:
raise HTTPBadRequest(detail="Repository not found")
irm = InstalledRepositoryManager(app=self.app)
errors = irm.uninstall_repository(repository=repository, remove_from_disk=kwd.get('remove_from_disk', True))
if not errors:
action = 'removed' if kwd.get('remove_from_disk', True) else 'deactivated'
return {'message': 'The repository named %s has been %s.' % (repository.name, action)}
else:
raise Exception('Attempting to uninstall tool dependencies for repository named %s resulted in errors: %s' % (repository.name, errors))

@expose_api
def repair_repository_revision( self, trans, payload, **kwd ):
"""
Expand Down
18 changes: 18 additions & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,12 +826,30 @@ def populate_api_routes( webapp, app ):
action='status',
conditions=dict( method=[ "GET" ] ) )

webapp.mapper.connect( 'install_repository',
'/api/tool_shed_repositories',
controller='tool_shed_repositories',
action='install_repository_revision',
conditions=dict( method=[ 'POST' ] ) )

webapp.mapper.connect( 'install_repository',
'/api/tool_shed_repositories/install',
controller='tool_shed_repositories',
action='install',
conditions=dict( method=[ 'POST' ] ) )

webapp.mapper.connect( 'tool_shed_repository',
'/api/tool_shed_repositories',
controller='tool_shed_repositories',
action='uninstall_repository',
conditions=dict( method=[ "DELETE" ]))

webapp.mapper.connect( 'tool_shed_repository',
'/api/tool_shed_repositories/{id}',
controller='tool_shed_repositories',
action='uninstall_repository',
conditions=dict( method=[ "DELETE" ]))

# Galaxy API for tool shed features.
webapp.mapper.resource( 'tool_shed_repository',
'tool_shed_repositories',
Expand Down

0 comments on commit 67c6686

Please sign in to comment.