def add_artifacts(ref_ids, update_solr=True, update_refs=True): '''Add the referenced artifacts to SOLR and shortlinks''' from allura import model as M from allura.lib.search import find_shortlinks, solarize exceptions = [] solr_updates = [] with _indexing_disabled(M.session.artifact_orm_session._get()): for ref in M.ArtifactReference.query.find(dict(_id={'$in': ref_ids})): try: artifact = ref.artifact s = solarize(artifact) if s is None: continue if update_solr: solr_updates.append(s) if update_refs: if isinstance(artifact, M.Snapshot): continue ref.references = [ link.ref_id for link in find_shortlinks(s['text']) ] except Exception: log.error('Error indexing artifact %s', ref._id) exceptions.append(sys.exc_info()) g.solr.add(solr_updates) if len(exceptions) == 1: raise exceptions[0][0], exceptions[0][1], exceptions[0][2] if exceptions: raise CompoundError(*exceptions)
def raise_exc(): errs = [] for x in range(10): try: assert False, 'assert %d' % x except: errs.append(sys.exc_info()) raise CompoundError(*errs)
def event(event_type, *args, **kwargs): exceptions = [] for t in event_handler.listeners[event_type]: try: t(event_type, *args, **kwargs) except: exceptions.append(sys.exc_info()) if exceptions: if len(exceptions) == 1: raise exceptions[0][0], exceptions[0][1], exceptions[0][2] else: raise CompoundError(*exceptions)
def add_artifacts(ref_ids, update_solr=True, update_refs=True, solr_hosts=None): ''' Add the referenced artifacts to SOLR and shortlinks. :param solr_hosts: a list of solr hosts to use instead of the defaults :type solr_hosts: [str] ''' from allura import model as M from allura.lib.search import find_shortlinks exceptions = [] solr_updates = [] with _indexing_disabled(M.session.artifact_orm_session._get()): for ref in M.ArtifactReference.query.find(dict(_id={'$in': ref_ids})): try: artifact = ref.artifact if artifact is None: continue # c.app is normally set, so keep using it. During a reindex its not though, so set it from artifact with h.push_config(c, app=getattr(c, 'app', None) or artifact.app): s = artifact.solarize() if s is None: continue if update_solr: solr_updates.append(s) if update_refs: if isinstance(artifact, M.Snapshot): continue # Find shortlinks in the raw text, not the escaped html # created by the `solarize()`. link_text = artifact.index().get('text') or '' shortlinks = find_shortlinks(link_text) ref.references = [link.ref_id for link in shortlinks] except Exception: log.error('Error indexing artifact %s', ref._id) exceptions.append(sys.exc_info()) __get_solr(solr_hosts).add(solr_updates) if len(exceptions) == 1: six.reraise(exceptions[0][0], exceptions[0][1], exceptions[0][2]) if exceptions: raise CompoundError(*exceptions)
def add_artifacts(ref_ids, update_solr=True, update_refs=True, solr_hosts=None): ''' Add the referenced artifacts to SOLR and shortlinks. :param solr_hosts: a list of solr hosts to use instead of the defaults :type solr_hosts: [str] ''' from allura import model as M from allura.lib.search import find_shortlinks, solarize if solr_hosts: solr = make_solr_from_config(solr_hosts) else: solr = g.solr exceptions = [] solr_updates = [] with _indexing_disabled(M.session.artifact_orm_session._get()): for ref in M.ArtifactReference.query.find(dict(_id={'$in': ref_ids})): try: artifact = ref.artifact s = solarize(artifact) if s is None: continue if update_solr: solr_updates.append(s) if update_refs: if isinstance(artifact, M.Snapshot): continue # Find shortlinks in the raw text, not the escaped html # created by the `solarize()`. ref.references = [ link.ref_id for link in find_shortlinks(artifact.index().get('text') or '')] except Exception: log.error('Error indexing artifact %s', ref._id) exceptions.append(sys.exc_info()) solr.add(solr_updates) if len(exceptions) == 1: raise exceptions[0][0], exceptions[0][1], exceptions[0][2] if exceptions: raise CompoundError(*exceptions)