def set_peek(self, dataset, line_count=None, is_multi_byte=False, WIDTH=256, skipchars=None, line_wrap=True): """ Set the peek. This method is used by various subclasses of Text. """ if not dataset.dataset.purged: # The file must exist on disk for the get_file_peek() method dataset.peek = get_file_peek(dataset.file_name, WIDTH=WIDTH, skipchars=skipchars, line_wrap=line_wrap) if line_count is None: # See if line_count is stored in the metadata if dataset.metadata.data_lines: dataset.blurb = "%s %s" % (util.commaify(str(dataset.metadata.data_lines)), inflector.cond_plural(dataset.metadata.data_lines, self.line_class)) else: # Number of lines is not known ( this should not happen ), and auto-detect is # needed to set metadata # This can happen when the file is larger than max_optional_metadata_filesize. if int(dataset.get_size()) <= 1048576: # Small dataset, recount all lines and reset peek afterward. lc = self.count_data_lines(dataset) dataset.metadata.data_lines = lc dataset.blurb = "%s %s" % (util.commaify(str(lc)), inflector.cond_plural(lc, self.line_class)) else: est_lines = self.estimate_file_lines(dataset) dataset.blurb = "~%s %s" % (util.commaify(util.roundify(str(est_lines))), inflector.cond_plural(est_lines, self.line_class)) else: dataset.blurb = "%s %s" % (util.commaify(str(line_count)), inflector.cond_plural(line_count, self.line_class)) else: dataset.peek = 'file does not exist' dataset.blurb = 'file purged from disk'
def set_peek( self, dataset, line_count=None, is_multi_byte=False, WIDTH=256, skipchars=[] ): """ Set the peek. This method is used by various subclasses of Text. """ if not dataset.dataset.purged: # The file must exist on disk for the get_file_peek() method dataset.peek = get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte, WIDTH=WIDTH, skipchars=skipchars ) if line_count is None: # See if line_count is stored in the metadata if dataset.metadata.data_lines: dataset.blurb = "%s %s" % ( util.commaify( str(dataset.metadata.data_lines) ), inflector.cond_plural(dataset.metadata.data_lines, self.line_class) ) else: # Number of lines is not known ( this should not happen ), and auto-detect is # needed to set metadata # This can happen when the file is larger than max_optional_metadata_filesize. if int(dataset.get_size()) <= 1048576: #Small dataset, recount all lines and reset peek afterward. lc = self.count_data_lines(dataset) dataset.metadata.data_lines = lc dataset.blurb = "%s %s" % ( util.commaify( str(lc) ), inflector.cond_plural(lc, self.line_class) ) else: est_lines = self.estimate_file_lines(dataset) dataset.blurb = "~%s %s" % ( util.commaify(util.roundify(str(est_lines))), inflector.cond_plural(est_lines, self.line_class) ) else: dataset.blurb = "%s %s" % ( util.commaify( str(line_count) ), inflector.cond_plural(line_count, self.line_class) ) else: dataset.peek = 'file does not exist' dataset.blurb = 'file purged from disk'
def delete_repository_metadata(self, trans, **kwd): message = escape(kwd.get("message", "")) status = kwd.get("status", "done") id = kwd.get("id", None) if id: ids = util.listify(id) count = 0 for repository_metadata_id in ids: repository_metadata = metadata_util.get_repository_metadata_by_id(trans.app, repository_metadata_id) trans.sa_session.delete(repository_metadata) trans.sa_session.flush() count += 1 if count: message = "Deleted %d repository metadata %s" % (count, inflector.cond_plural(len(ids), "record")) else: message = "No repository metadata ids received for deleting." status = "error" trans.response.send_redirect( web.url_for( controller="admin", action="browse_repository_metadata", message=util.sanitize_text(message), status=status, ) )
def delete_repository_metadata(self, trans, **kwd): params = util.Params(kwd) message = util.restore_text(params.get('message', '')) status = params.get('status', 'done') id = kwd.get('id', None) if id: ids = util.listify(id) count = 0 for repository_metadata_id in ids: repository_metadata = get_repository_metadata_by_id( trans, repository_metadata_id) trans.sa_session.delete(repository_metadata) trans.sa_session.flush() count += 1 if count: message = "Deleted %d repository metadata %s" % ( count, inflector.cond_plural(len(ids), "record")) else: message = "No repository metadata ids received for deleting." status = 'error' trans.response.send_redirect( web.url_for(controller='admin', action='browse_repository_metadata', message=util.sanitize_text(message), status=status))
def delete_repository( self, trans, **kwd ): message = kwd.get( 'message', '' ) status = kwd.get( 'status', 'done' ) id = kwd.get( 'id', None ) if id: # Deleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id. ids = util.listify( id ) count = 0 deleted_repositories = "" for repository_id in ids: repository = suc.get_repository_in_tool_shed( trans, repository_id ) if repository: if not repository.deleted: # Mark all installable repository_metadata records as not installable. for repository_metadata in repository.downloadable_revisions: repository_metadata.downloadable = False trans.sa_session.add( repository_metadata ) repository.deleted = True trans.sa_session.add( repository ) trans.sa_session.flush() count += 1 deleted_repositories += " %s " % repository.name if count: message = "Deleted %d %s: %s" % ( count, inflector.cond_plural( len( ids ), "repository" ), deleted_repositories ) else: message = "All selected repositories were already marked deleted." else: message = "No repository ids received for deleting." status = 'error' trans.response.send_redirect( web.url_for( controller='admin', action='browse_repositories', message=util.sanitize_text( message ), status=status ) )
def undelete_repository(self, trans, **kwd): params = util.Params(kwd) message = util.restore_text(params.get('message', '')) status = params.get('status', 'done') id = kwd.get('id', None) if id: # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id. ids = util.listify(id) count = 0 undeleted_repositories = "" for repository_id in ids: repository = get_repository(trans, repository_id) if repository.deleted: repository.deleted = False trans.sa_session.add(repository) trans.sa_session.flush() count += 1 undeleted_repositories += " %s" % repository.name if count: message = "Undeleted %d %s: %s" % ( count, inflector.cond_plural( count, "repository"), undeleted_repositories) else: message = "No selected repositories were marked deleted, so they could not be undeleted." else: message = "No repository ids received for undeleting." status = 'error' trans.response.send_redirect( web.url_for(controller='admin', action='browse_repositories', message=util.sanitize_text(message), status='done'))
def undelete_repository( self, trans, **kwd ): params = util.Params( kwd ) message = util.restore_text( params.get( 'message', '' ) ) status = params.get( 'status', 'done' ) id = kwd.get( 'id', None ) if id: # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id. ids = util.listify( id ) count = 0 undeleted_repositories = "" for repository_id in ids: repository = get_repository( trans, repository_id ) if repository.deleted: repository.deleted = False trans.sa_session.add( repository ) trans.sa_session.flush() count += 1 undeleted_repositories += " %s" % repository.name if count: message = "Undeleted %d %s: %s" % ( count, inflector.cond_plural( count, "repository" ), undeleted_repositories ) else: message = "No selected repositories were marked deleted, so they could not be undeleted." else: message = "No repository ids received for undeleting." status = 'error' trans.response.send_redirect( web.url_for( controller='admin', action='browse_repositories', message=util.sanitize_text( message ), status='done' ) )
def reset_metadata_on_all_repositories( self, trans, **kwd ): params = util.Params( kwd ) message = util.restore_text( params.get( 'message', '' ) ) status = params.get( 'status', 'done' ) if 'reset_metadata_on_all_repositories_button' in kwd: successful_count = 0 unsuccessful_count = 0 for repository in trans.sa_session.query( trans.model.Repository ) \ .filter( trans.model.Repository.table.c.deleted == False ): try: error_message, status = reset_all_metadata_on_repository( trans, trans.security.encode_id( repository.id ) ) if status not in [ 'ok' ] and error_message: log.debug( "Error attempting to reset metadata on repository '%s': %s" % ( repository.name, error_message ) ) unsuccessful_count += 1 elif status in [ 'ok' ] and error_message: log.debug( "Successfully reset metadata on repository %s, but encountered this problem: %s" % ( repository.name, error_message ) ) successful_count += 1 else: log.debug( "Successfully reset metadata on repository %s" % repository.name ) 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', action='browse_repository_metadata', webapp='community', message=util.sanitize_text( message ), status=status ) )
def reset_metadata_on_selected_repositories(self, user, **kwd): """ Inspect the repository changelog to reset metadata for all appropriate changeset revisions. This method is called from both Galaxy and the Tool Shed. """ repository_ids = util.listify(kwd.get('repository_ids', None)) message = '' status = 'done' if repository_ids: successful_count = 0 unsuccessful_count = 0 for repository_id in repository_ids: try: repository = get_installed_tool_shed_repository( self.app, repository_id) self.set_repository(repository) self.reset_all_metadata_on_installed_repository() if self.invalid_file_tups: message = generate_message_for_invalid_tools( self.app, self.invalid_file_tups, repository, None, as_html=False) log.debug(message) unsuccessful_count += 1 else: log.debug( "Successfully reset metadata on repository %s owned by %s" % (str(repository.name), str(repository.owner))) successful_count += 1 except Exception: log.exception( "Error attempting to reset metadata on repository %s", str(repository.name)) 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")) else: message = 'Select at least one repository to on which to reset all metadata.' status = 'error' return message, status
def reset_metadata_on_selected_repositories( self, user, **kwd ): """ Inspect the repository changelog to reset metadata for all appropriate changeset revisions. This method is called from both Galaxy and the Tool Shed. """ repository_ids = util.listify( kwd.get( 'repository_ids', None ) ) message = '' status = 'done' if repository_ids: successful_count = 0 unsuccessful_count = 0 for repository_id in repository_ids: try: repository = repository_util.get_installed_tool_shed_repository( self.app, repository_id ) self.set_repository( repository ) self.reset_all_metadata_on_installed_repository() if self.invalid_file_tups: message = tool_util.generate_message_for_invalid_tools( self.app, self.invalid_file_tups, repository, None, as_html=False ) log.debug( message ) unsuccessful_count += 1 else: log.debug( "Successfully reset metadata on repository %s owned by %s" % ( str( repository.name ), str( repository.owner ) ) ) successful_count += 1 except: log.exception( "Error attempting to reset metadata on repository %s", str( repository.name ) ) 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" ) ) else: message = 'Select at least one repository to on which to reset all metadata.' status = 'error' return message, status
def undelete_repository(self, trans, **kwd): message = escape(kwd.get('message', '')) status = kwd.get('status', 'done') id = kwd.get('id', None) if id: # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id. ids = util.listify(id) count = 0 undeleted_repositories = "" for repository_id in ids: repository = suc.get_repository_in_tool_shed( trans.app, repository_id) if repository: if repository.deleted: # Inspect all repository_metadata records to determine those that are installable, and mark # them accordingly. for repository_metadata in repository.metadata_revisions: metadata = repository_metadata.metadata if metadata: if metadata_util.is_downloadable(metadata): repository_metadata.downloadable = True trans.sa_session.add(repository_metadata) # Mark the repository admin role as not deleted. repository_admin_role = repository.admin_role if repository_admin_role is not None: repository_admin_role.deleted = False trans.sa_session.add(repository_admin_role) repository.deleted = False trans.sa_session.add(repository) trans.sa_session.flush() if not repository.deprecated: # Update the repository registry. trans.app.repository_registry.add_entry(repository) count += 1 undeleted_repositories += " %s" % repository.name if count: message = "Undeleted %d %s: %s" % ( count, inflector.cond_plural( count, "repository"), undeleted_repositories) else: message = "No selected repositories were marked deleted, so they could not be undeleted." else: message = "No repository ids received for undeleting." status = 'error' trans.response.send_redirect( web.url_for(controller='admin', action='browse_repositories', message=util.sanitize_text(message), status='done'))
def undelete_repository(self, trans, **kwd): message = escape(kwd.get("message", "")) id = kwd.get("id", None) if id: # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id. ids = util.listify(id) count = 0 undeleted_repositories = "" for repository_id in ids: repository = suc.get_repository_in_tool_shed(trans.app, repository_id) if repository: if repository.deleted: # Inspect all repository_metadata records to determine those that are installable, and mark # them accordingly. for repository_metadata in repository.metadata_revisions: metadata = repository_metadata.metadata if metadata: if metadata_util.is_downloadable(metadata): repository_metadata.downloadable = True trans.sa_session.add(repository_metadata) # Mark the repository admin role as not deleted. repository_admin_role = repository.admin_role if repository_admin_role is not None: repository_admin_role.deleted = False trans.sa_session.add(repository_admin_role) repository.deleted = False trans.sa_session.add(repository) trans.sa_session.flush() if not repository.deprecated: # Update the repository registry. trans.app.repository_registry.add_entry(repository) count += 1 undeleted_repositories += " %s" % repository.name if count: message = "Undeleted %d %s: %s" % ( count, inflector.cond_plural(count, "repository"), undeleted_repositories, ) else: message = "No selected repositories were marked deleted, so they could not be undeleted." else: message = "No repository ids received for undeleting." trans.response.send_redirect( web.url_for( controller="admin", action="browse_repositories", message=util.sanitize_text(message), status="done" ) )
def reset_user_password(self, trans, **kwd): user_id = kwd.get('id', None) if not user_id: message = "No users received for resetting passwords." trans.response.send_redirect( web.url_for(controller='admin', action='users', message=message, status='error')) user_ids = util.listify(user_id) if 'reset_user_password_button' in kwd: message = '' status = '' for user_id in user_ids: user = get_user(trans, user_id) password = kwd.get('password', None) confirm = kwd.get('confirm', None) if len(password) < 6: message = "Use a password of at least 6 characters." status = 'error' break elif password != confirm: message = "Passwords do not match." status = 'error' break else: user.set_password_cleartext(password) trans.sa_session.add(user) trans.sa_session.flush() if not message and not status: message = "Passwords reset for %d %s." % (len( user_ids), inflector.cond_plural(len(user_ids), 'user')) status = 'done' trans.response.send_redirect( web.url_for(controller='admin', action='users', message=util.sanitize_text(message), status=status)) users = [get_user(trans, user_id) for user_id in user_ids] if len(user_ids) > 1: user_id = ','.join(user_ids) return trans.fill_template( '/webapps/tool_shed/admin/user/reset_password.mako', id=user_id, users=users, password='', confirm='')
def delete_repository(self, trans, **kwd): message = escape(kwd.get("message", "")) status = kwd.get("status", "done") id = kwd.get("id", None) if id: # Deleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id. ids = util.listify(id) count = 0 deleted_repositories = "" for repository_id in ids: repository = suc.get_repository_in_tool_shed(trans.app, repository_id) if repository: if not repository.deleted: # Mark all installable repository_metadata records as not installable. for repository_metadata in repository.downloadable_revisions: repository_metadata.downloadable = False trans.sa_session.add(repository_metadata) # Mark the repository admin role as deleted. repository_admin_role = repository.admin_role if repository_admin_role is not None: repository_admin_role.deleted = True trans.sa_session.add(repository_admin_role) repository.deleted = True trans.sa_session.add(repository) trans.sa_session.flush() # Update the repository registry. trans.app.repository_registry.remove_entry(repository) count += 1 deleted_repositories += " %s " % repository.name if count: message = "Deleted %d %s: %s" % ( count, inflector.cond_plural(len(ids), "repository"), escape(deleted_repositories), ) else: message = "All selected repositories were already marked deleted." else: message = "No repository ids received for deleting." status = "error" trans.response.send_redirect( web.url_for( controller="admin", action="browse_repositories", message=util.sanitize_text(message), status=status ) )
def reset_user_password(self, trans, **kwd): user_id = kwd.get('id', None) if not user_id: message = "No users received for resetting passwords." trans.response.send_redirect(web.url_for(controller='admin', action='users', message=message, status='error')) user_ids = util.listify(user_id) if 'reset_user_password_button' in kwd: message = '' status = '' for user_id in user_ids: user = get_user(trans, user_id) password = kwd.get('password', None) confirm = kwd.get('confirm', None) if len(password) < 6: message = "Use a password of at least 6 characters." status = 'error' break elif password != confirm: message = "Passwords do not match." status = 'error' break else: user.set_password_cleartext(password) trans.sa_session.add(user) trans.sa_session.flush() if not message and not status: message = "Passwords reset for %d %s." % (len(user_ids), inflector.cond_plural(len(user_ids), 'user')) status = 'done' trans.response.send_redirect(web.url_for(controller='admin', action='users', message=util.sanitize_text(message), status=status)) users = [get_user(trans, user_id) for user_id in user_ids] if len(user_ids) > 1: user_id = ','.join(user_ids) return trans.fill_template('/webapps/tool_shed/admin/user/reset_password.mako', id=user_id, users=users, password='', confirm='')
def delete_repository_metadata( self, trans, **kwd ): message = kwd.get( 'message', '' ) status = kwd.get( 'status', 'done' ) id = kwd.get( 'id', None ) if id: ids = util.listify( id ) count = 0 for repository_metadata_id in ids: repository_metadata = metadata_util.get_repository_metadata_by_id( trans.app, repository_metadata_id ) trans.sa_session.delete( repository_metadata ) trans.sa_session.flush() count += 1 if count: message = "Deleted %d repository metadata %s" % ( count, inflector.cond_plural( len( ids ), "record" ) ) else: message = "No repository metadata ids received for deleting." status = 'error' trans.response.send_redirect( web.url_for( controller='admin', action='browse_repository_metadata', message=util.sanitize_text( message ), status=status ) )
def undelete_repository( self, trans, **kwd ): message = kwd.get( 'message', '' ) status = kwd.get( 'status', 'done' ) id = kwd.get( 'id', None ) if id: # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id. ids = util.listify( id ) count = 0 undeleted_repositories = "" for repository_id in ids: repository = suc.get_repository_in_tool_shed( trans, repository_id ) if repository: if repository.deleted: # Inspect all repository_metadata records to determine those that are installable, and mark them accordingly. for repository_metadata in repository.metadata_revisions: metadata = repository_metadata.metadata if metadata: if metadata_util.is_downloadable( metadata ): repository_metadata.downloadable = True trans.sa_session.add( repository_metadata ) repository.deleted = False trans.sa_session.add( repository ) trans.sa_session.flush() count += 1 undeleted_repositories += " %s" % repository.name if count: message = "Undeleted %d %s: %s" % ( count, inflector.cond_plural( count, "repository" ), undeleted_repositories ) else: message = "No selected repositories were marked deleted, so they could not be undeleted." else: message = "No repository ids received for undeleting." status = 'error' trans.response.send_redirect( web.url_for( controller='admin', action='browse_repositories', message=util.sanitize_text( message ), status='done' ) )