From 02c71550dadd6e5d97ce1c96f24c004eb65a397b Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Thu, 26 Jun 2014 13:54:51 -0400 Subject: [PATCH] Add a confirmation page when purging installed repositories and include a fix for purging an installed repository that has a tool version lineage chain. --- .../galaxy/controllers/admin_toolshed.py | 26 ++++--- .../installed_repository_manager.py | 40 +++++----- .../purge_repository_confirmation.mako | 74 +++++++++++++++++++ 3 files changed, 111 insertions(+), 29 deletions(-) create mode 100644 templates/admin/tool_shed_repository/purge_repository_confirmation.mako 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 name="javascripts()"> + ${parent.javascripts()} + + +${render_galaxy_repository_actions( repository )} + +%if message: + ${render_msg( message, status )} +%endif + +
+

+ Purging the repository named ${repository.name} will result in deletion of all records for the + following associated items from the database. Click the Purge button to purge this repository + and its associated items. +

+
+ +
+
Purge tool shed repository ${repository.name}
+
+ <% + tool_versions = 0 + tool_dependencies = 0 + required_repositories = 0 + orphan_repository_repository_dependency_association_records = 0 + orphan_repository_dependency_records = 0 + # Count this repository's tool version lineage chain links that will be purged. + for tool_version in repository.tool_versions: + for tool_version_association in tool_version.parent_tool_association: + tool_versions += 1 + for tool_version_association in tool_version.child_tool_association: + tool_versions += 1 + tool_versions += 1 + # Count this repository's associated tool dependencies that will be purged. + for tool_dependency in repository.tool_dependencies: + tool_dependencies += 1 + # Count this repository's associated required repositories that will be purged. + for rrda in repository.required_repositories: + required_repositories += 1 + # Count any "orphan" repository_dependency records associated with the repository but not with any + # repository_repository_dependency_association records that will be purged. + for orphan_repository_dependency in \ + trans.sa_session.query( trans.app.install_model.RepositoryDependency ) \ + .filter( trans.app.install_model.RepositoryDependency.table.c.tool_shed_repository_id == repository.id ): + for orphan_rrda in \ + trans.sa_session.query( trans.app.install_model.RepositoryRepositoryDependencyAssociation ) \ + .filter( trans.app.install_model.RepositoryRepositoryDependencyAssociation.table.c.repository_dependency_id == orphan_repository_dependency.id ): + orphan_repository_repository_dependency_association_records += 1 + orphan_repository_dependency_records += 1 + %> + + + + + + +
Tool version records${tool_versions}
Tool dependency records${tool_dependencies}
Repository dependency records${required_repositories}
Orphan repository_repository_dependency_association records${orphan_repository_repository_dependency_association_records}
Orphan repository_dependency records${orphan_repository_dependency_records}
+
+
+ +
+
+
+