Example #1
0
def refreshCatalog(self, clear=0, pghandler=None, quick=False):
    """ re-index everything we can find """

    cat = self._catalog
    paths = cat.paths.values()
    if clear:
        paths = tuple(paths)
        cat.clear()

    num_objects = len(paths)
    if pghandler:
        pghandler.init('Refreshing catalog: %s' % self.absolute_url(1),
                       num_objects)

    for i in xrange(num_objects):
        if pghandler:
            pghandler.report(i)

        p = paths[i]
        obj = self.resolve_path(p)
        if obj is None:
            obj = self.resolve_url(p, self.REQUEST)
        if obj is not None:
            try:
                self.catalog_object(obj, p, pghandler=pghandler, quick=quick)
            except ConflictError:
                raise
            except Exception:
                LOG.error('Recataloging object at %s failed' % p,
                          exc_info=sys.exc_info())

    if pghandler:
        pghandler.finish()
Example #2
0
def catalogObject(self, object, uid, threshold=None, idxs=None,
                  update_metadata=1, quick=False):
    """
    Adds an object to the Catalog by iteratively applying it to
    all indexes.

    'object' is the object to be cataloged

    'uid' is the unique Catalog identifier for this object

    If 'idxs' is specified (as a sequence), apply the object only
    to the named indexes.

    If 'update_metadata' is true (the default), also update metadata for
    the object.  If the object is new to the catalog, this flag has
    no effect (metadata is always created for new objects).

    """

    if idxs is None:
        idxs = []

    index = self.uids.get(uid, None)

    if index is None:  # we are inserting new data
        index = self.updateMetadata(object, uid, None)
        self._length.change(1)
        self.uids[uid] = index
        self.paths[index] = uid

    elif update_metadata:  # we are updating and we need to update metadata
        self.updateMetadata(object, uid, index)

    # do indexing
    total = 0

    if idxs == []:
        use_indexes = self.indexes.keys()
    else:
        use_indexes = idxs

    for name in use_indexes:
        x = self.getIndex(name)
        if quick and x.meta_type in SLOW_INDEXES:
            continue
        if hasattr(x, 'index_object'):
            blah = x.index_object(index, object, threshold)
            total = total + blah
        else:
            LOG.error('catalogObject was passed bad index '
                      'object %s.' % str(x))

    return total
Example #3
0
def uncatalogObject(self, uid):
    """
    Uncatalog and object from the Catalog.  and 'uid' is a unique
    Catalog identifier

    Note, the uid must be the same as when the object was
    catalogued, otherwise it will not get removed from the catalog

    This method should not raise an exception if the uid cannot
    be found in the catalog.

    """
    data = self.data
    uids = self.uids
    paths = self.paths
    indexes = self.indexes.keys()
    rid = uids.get(uid, None)

    if rid is not None:
        for name in indexes:
            x = self.getIndex(name)
            if hasattr(x, 'unindex_object'):
                try:
                    x.unindex_object(rid)
                except KeyError:
                    LOG.error('uncatalogObject unsuccessfully '
                              'attempted to unindex uid %s '
                              'for index %s. ' % (str(uid), name))
                    continue
        del data[rid]
        del paths[rid]
        del uids[uid]
        self._length.change(-1)

    else:
        LOG.error('uncatalogObject unsuccessfully '
                  'attempted to uncatalog an object '
                  'with a uid of %s. ' % str(uid))