Add a confirmation page when purging installed repositories and include a fix for purging an installed repository that has a tool version lineage chain.

This commit is contained in:
Greg Von Kuster
2014-06-26 13:54:51 -04:00
parent bc460f36a7
commit 02c71550da
3 changed files with 111 additions and 29 deletions
@@ -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 <b>New</b> 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.'
@@ -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()
@@ -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
<div class="warningmessage">
<p>
Purging the repository named <b>${repository.name}</b> will result in deletion of all records for the
following associated items from the database. Click the <b>Purge</b> button to purge this repository
and its associated items.
</p>
</div>
<div class="toolForm">
<div class="toolFormTitle">Purge tool shed repository <b>${repository.name}</b></div>
<form name="purge_repository" id="purge_repository" action="${h.url_for( controller='admin_toolshed', action='purge_repository', id=trans.security.encode_id( repository.id ) )}" method="post" >
<%
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
%>
<table class="grid">
<tr><td>Tool version records</td><td>${tool_versions}</td><tr>
<tr><td>Tool dependency records</td><td>${tool_dependencies}</td><tr>
<tr><td>Repository dependency records</td><td>${required_repositories}</td><tr>
<tr><td>Orphan repository_repository_dependency_association records</td><td>${orphan_repository_repository_dependency_association_records}</td><tr>
<tr><td>Orphan repository_dependency records</td><td>${orphan_repository_dependency_records}</td><tr>
</table>
<div style="clear: both"></div>
<div class="form-row">
<input type="submit" name="purge_repository_button" value="Purge"/>
</div>
</form>
</div>
</div>