commit/galaxy-central: greg: Add the abiltiy for a Galaxy admin to reset metadata on selected installed tool shed repositories.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/b037978114ca/ changeset: b037978114ca user: greg date: 2012-10-11 16:20:57 summary: Add the abiltiy for a Galaxy admin to reset metadata on selected installed tool shed repositories. affected #: 2 files diff -r 0684f69e527da908b27fc78e0f0d15ddef5ea33b -r b037978114caede484df1b25bd4004e0591820f5 lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py --- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py @@ -1447,7 +1447,59 @@ status=status ) @web.expose @web.require_admin - def reset_repository_metadata( self, trans, id ): + def reset_metadata_on_selected_repositories( self, trans, **kwd ): + # TODO: merge this with the similar method in the repository controller. + params = util.Params( kwd ) + message = util.restore_text( params.get( 'message', '' ) ) + status = params.get( 'status', 'done' ) + repository_ids = util.listify( kwd.get( 'repository_names_by_owner', None ) ) + if 'reset_metadata_on_selected_repositories_button' in kwd: + if repository_ids: + successful_count = 0 + unsuccessful_count = 0 + for repository_id in repository_ids: + repository = get_repository( trans, repository_id ) + try: + invalid_file_tups, metadata_dict = self.reset_repository_metadata( trans, + trans.security.encode_id( repository.id ), + resetting_all_repositories=True ) + if invalid_file_tups: + unsuccessful_count += 1 + else: + successful_count += 1 + except Exception, e: + log.debug( "Error attempting to reset metadata on repository '%s': %s" % ( repository.name, str( e ) ) ) + unsuccessful_count += 1 + message = "Successfully reset metadata on %d %s. " % ( successful_count, + inflector.cond_plural( successful_count, "repository" ) ) + if unsuccessful_count: + message += "Error setting metadata on %d %s - see the paster log for details. " % ( unsuccessful_count, + inflector.cond_plural( unsuccessful_count, + "repository" ) ) + trans.response.send_redirect( web.url_for( controller='admin_toolshed', + action='browse_repositories', + message=util.sanitize_text( message ), + status=status ) ) + else: + 'Select at least one repository to on which to reset all metadata.' + status = 'error' + repositories_select_field = SelectField( name='repository_names_by_owner', + multiple=True, + display='checkboxes' ) + for repository in trans.sa_session.query( trans.model.ToolShedRepository ) \ + .filter( trans.model.ToolShedRepository.table.c.uninstalled == False ) \ + .order_by( trans.model.ToolShedRepository.table.c.name, + trans.model.ToolShedRepository.table.c.owner ): + option_label = '%s (%s)' % ( repository.name, repository.owner ) + option_value = trans.security.encode_id( repository.id ) + repositories_select_field.add_option( option_label, option_value ) + return trans.fill_template( '/admin/tool_shed_repository/reset_metadata_on_selected_repositories.mako', + repositories_select_field=repositories_select_field, + message=message, + status=status ) + @web.expose + @web.require_admin + def reset_repository_metadata( self, trans, id, resetting_all_repositories=False ): """Reset all metadata on the installed tool shed repository.""" repository = get_repository( trans, id ) tool_shed_url = get_url_from_repository_tool_shed( trans.app, repository ) @@ -1465,23 +1517,33 @@ updating_installed_repository=False ) repository.metadata = metadata_dict if metadata_dict != original_metadata_dict: - update_in_shed_tool_config( trans.app, repository )#def update_in_shed_tool_config( trans, shed_tool_conf_dict, elem_list ): + update_in_shed_tool_config( trans.app, repository ) trans.sa_session.add( repository ) trans.sa_session.flush() - message = 'Metadata has been reset on repository <b>%s</b>.' % repository.name - status = 'done' + if resetting_all_repositories: + log.debug( 'Metadata has been reset on repository %s.' % repository.name ) + else: + message = 'Metadata has been reset on repository <b>%s</b>.' % repository.name + status = 'done' else: - message = 'Metadata did not need to be reset on repository <b>%s</b>.' % repository.name - status = 'done' + if resetting_all_repositories: + log.debug( 'Metadata did not need to be reset on repository %s.' % repository.name ) + else: + message = 'Metadata did not need to be reset on repository <b>%s</b>.' % repository.name + status = 'done' else: - message = 'Error locating installation directory for repository <b>%s</b>.' % repository.name - status = 'error' - new_kwd = dict( id=id, - message=message, - status=status ) - return trans.response.send_redirect( web.url_for( controller='admin_toolshed', - action='manage_repository', - **new_kwd ) ) + if resetting_all_repositories: + log.debug( 'Error locating installation directory for repository %s.' % repository.name ) + else: + message = 'Error locating installation directory for repository <b>%s</b>.' % repository.name + status = 'error' + if resetting_all_repositories: + return invalid_file_tups, metadata_dict + else: + new_kwd = dict( id=id, message=message, status=status ) + return trans.response.send_redirect( web.url_for( controller='admin_toolshed', + action='manage_repository', + **new_kwd ) ) @web.expose @web.require_admin def reset_to_install( self, trans, **kwd ): diff -r 0684f69e527da908b27fc78e0f0d15ddef5ea33b -r b037978114caede484df1b25bd4004e0591820f5 templates/admin/tool_shed_repository/reset_metadata_on_selected_repositories.mako --- /dev/null +++ b/templates/admin/tool_shed_repository/reset_metadata_on_selected_repositories.mako @@ -0,0 +1,71 @@ +<%inherit file="/base.mako"/> +<%namespace file="/message.mako" import="render_msg" /> + +<%def name="local_javascripts()"> + <script type="text/javascript"> + function checkAllFields() + { + var chkAll = document.getElementById('checkAll'); + var checks = document.getElementsByTagName('input'); + var boxLength = checks.length; + var allChecked = false; + var totalChecked = 0; + if ( chkAll.checked == true ) + { + for ( i=0; i < boxLength; i++ ) + { + if ( checks[i].name.indexOf( 'repository_names_by_owner' ) != -1) + { + checks[i].checked = true; + } + } + } + else + { + for ( i=0; i < boxLength; i++ ) + { + if ( checks[i].name.indexOf( 'repository_names_by_owner' ) != -1) + { + checks[i].checked = false + } + } + } + } + </script> +</%def> + +<%def name="javascripts()"> + ${parent.javascripts()} + ${local_javascripts()} +</%def> + +%if message: + ${render_msg( message, status )} +%endif + +<div class="warningmessage"> + Resetting metadata may take a while, so wait until this page redirects after clicking the <b>Reset metadata on selected repositories</b> button, as + doing anything else will not be helpful. +</div> + +<div class="toolForm"> + <div class="toolFormTitle">Reset all metadata on each selected tool shed repository</div> + <form name="reset_metadata_on_selected_repositories" id="reset_metadata_on_selected_repositories" action="${h.url_for( controller='admin_toolshed', action='reset_metadata_on_selected_repositories' )}" method="post" > + <div class="form-row"> + Check each repository for which you want to reset metadata. Repository names are followed by owners in parentheses. + </div> + <div style="clear: both"></div> + <div class="form-row"> + <input type="checkbox" id="checkAll" name=select_all_repositories_checkbox value="true" onclick='checkAllFields(1);'/><input type="hidden" name=select_all_repositories_checkbox value="true"/><b>Select/unselect all repositories</b> + </div> + <div style="clear: both"></div> + <div class="form-row"> + ${repositories_select_field.get_html()} + </div> + <div style="clear: both"></div> + <div class="form-row"> + <input type="submit" name="reset_metadata_on_selected_repositories_button" value="Reset metadata on selected repositories"/> + </div> + </form> + </div> +</div> Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket