diff --git a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py index ebb01b14fc3..2430ae83331 100644 --- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py @@ -102,7 +102,6 @@ class AdminToolshed( AdminGalaxy ): action='reset_to_install', **kwd ) ) if operation == "purge": - kwd[ 'purge_repository' ] = True return trans.response.send_redirect( web.url_for( controller='admin_toolshed', action='purge_repository', **kwd ) ) @@ -1269,18 +1268,25 @@ class AdminToolshed( AdminGalaxy ): new_kwd = {} if repository_id is not None: repository = suc.get_installed_tool_shed_repository( trans.app, repository_id ) - if repository: - if kwd.get( 'purge_repository', False ): - irm = trans.app.installed_repository_manager - purge_status, purge_message = irm.purge_repository( trans.app, repository ) - if purge_status == 'ok': - new_kwd[ 'status' ] = "done" + if repository.is_new: + if repository: + if kwd.get( 'purge_repository_button', False ): + irm = trans.app.installed_repository_manager + purge_status, purge_message = irm.purge_repository( repository ) + if purge_status == 'ok': + new_kwd[ 'status' ] = "done" + else: + new_kwd[ 'status' ] = 'error' + new_kwd[ 'message' ] = purge_message else: - new_kwd[ 'status' ] = 'error' - new_kwd[ 'message' ] = purge_message + return trans.fill_template( 'admin/tool_shed_repository/purge_repository_confirmation.mako', + repository=repository ) + else: + new_kwd[ 'status' ] = 'error' + new_kwd[ 'message' ] = 'Cannot locate the database record for the repository with encoded id %s.' % str( repository_id ) else: new_kwd[ 'status' ] = 'error' - new_kwd[ 'message' ] = 'Cannot locate the database record for the repository with encoded id %s.' % str( repository_id ) + new_kwd[ 'message' ] = 'Repositories must have a New status in order to be purged.' else: new_kwd[ 'status' ] = 'error' new_kwd[ 'message' ] = 'Invalid repository id value "None" received for repository to be purged.' diff --git a/lib/tool_shed/galaxy_install/installed_repository_manager.py b/lib/tool_shed/galaxy_install/installed_repository_manager.py index 154e265ceea..5239ae5ab5d 100644 --- a/lib/tool_shed/galaxy_install/installed_repository_manager.py +++ b/lib/tool_shed/galaxy_install/installed_repository_manager.py @@ -718,7 +718,7 @@ class InstalledRepositoryManager( object ): if installed_repository_dict[ 'display_path' ]: datatype_util.load_installed_display_applications( self.app, installed_repository_dict, deactivate=deactivate ) - def purge_repository( self, app, repository ): + def purge_repository( self, repository ): """Purge a repository with status New (a white ghost) from the database.""" sa_session = self.app.model.context.current status = 'ok' @@ -732,24 +732,26 @@ class InstalledRepositoryManager( object ): # Purge this repository's associated tool versions. if repository.tool_versions: for tool_version in repository.tool_versions: - try: - tool_version_association = tool_version.parent_tool_association - sa_session.delete( tool_version_association ) - sa_session.flush() - except Exception, e: - status = 'error' - message = 'Error attempting to purge tool_versions for the repository named %s with status %s: %s.' % \ - ( str( repository.name ), str( repository.status ), str( e ) ) - return status, message - try: - tool_version_association = tool_version.child_tool_association - sa_session.delete( tool_version_association ) - sa_session.flush() - except Exception, e: - status = 'error' - message = 'Error attempting to purge tool_versions for the repository named %s with status %s: %s.' % \ - ( str( repository.name ), str( repository.status ), str( e ) ) - return status, message + if tool_version.parent_tool_association: + for tool_version_association in tool_version.parent_tool_association: + try: + sa_session.delete( tool_version_association ) + sa_session.flush() + except Exception, e: + status = 'error' + message = 'Error attempting to purge tool_versions for the repository named %s with status %s: %s.' % \ + ( str( repository.name ), str( repository.status ), str( e ) ) + return status, message + if tool_version.child_tool_association: + for tool_version_association in tool_version.child_tool_association: + try: + sa_session.delete( tool_version_association ) + sa_session.flush() + except Exception, e: + status = 'error' + message = 'Error attempting to purge tool_versions for the repository named %s with status %s: %s.' % \ + ( str( repository.name ), str( repository.status ), str( e ) ) + return status, message try: sa_session.delete( tool_version ) sa_session.flush() diff --git a/templates/admin/tool_shed_repository/purge_repository_confirmation.mako b/templates/admin/tool_shed_repository/purge_repository_confirmation.mako new file mode 100644 index 00000000000..eda8431ef26 --- /dev/null +++ b/templates/admin/tool_shed_repository/purge_repository_confirmation.mako @@ -0,0 +1,74 @@ +<%inherit file="/base.mako"/> +<%namespace file="/message.mako" import="render_msg" /> +<%namespace file="/admin/tool_shed_repository/repository_actions_menu.mako" import="*" /> + +<%def name="stylesheets()"> + ${parent.stylesheets()} + ${h.css( "library" )} +%def> + +<%def name="javascripts()"> + ${parent.javascripts()} +%def> + +${render_galaxy_repository_actions( repository )} + +%if message: + ${render_msg( message, status )} +%endif + +
+ +