Esempio n. 1
0
def index_site(request, autocommit=True):
    """Index all site contents in internal catalog"""
    application = site_factory(request)
    if application is not None:
        try:
            set_local_registry(application.getSiteManager())
            catalog = get_utility(ICatalog)
            catalog.reset()
            transaction.savepoint()
            intids = get_utility(IIntIds)
            for index, document in enumerate(find_objects_providing(application, Interface)):
                if INoAutoIndex.providedBy(document):
                    continue
                if IBroken.providedBy(document):
                    print("Skipping broken object: {0!r}".format(document))
                else:
                    print("Indexing: {0!r}".format(document))
                    catalog.reindex_doc(intids.register(document), document)
                    if not index % 100:
                        transaction.savepoint()
        finally:
            set_local_registry(None)
        if autocommit:
            transaction.commit()
    return application
Esempio n. 2
0
def isBroken(obj, uid=None):
    """
    Check if the object is broken (missing or an implementation of
    :class:`ZODB.interfaces.IBroken`).

    :keyword str uid: A debugging aid, unless the obj is none,
      in which case it must be non-None to result in a True return.
      This makes no sense, so try to avoid passing objects that are None
      to this function.
    """
    if obj is None:
        msg = uid if uid is not None else ''
        logger.debug("Ignoring NULL object %s", msg)
        return uid is not None


    try:
        try:
            obj._p_activate()
        except (TypeError, AttributeError):
            pass
        return IBroken.providedBy(obj)
    except (POSKeyError, TypeError):
        # XXX: How can TypeError be raised by IBroken.providedBy?
        # Note that we only catch POSKeyError---anything else, like
        # KeyError or POSError, would be a lie. In particular, StorageError
        # is a type of POSError, which would indicate connection problems to the
        # ZODB, *not* a broken object.
        logger.debug("Ignoring broken object %s, %s", type(obj), uid)
        return True
Esempio n. 3
0
 def update(self):
     self.counter = dict()
     inc = dict(anzahl=0, entwurf=0, gesendet=0, verarbeitung=0)
     hFB = getUtility(IHomeFolderManager).homeFolderBase
     self.counter['HomeFolder'] = inc
     self.counter['HomeFolder']['anzahl'] = len(hFB)
     pf_c = 0
     for homefolder in hFB.values():
         for name, pf in homefolder.items():
             if not IBroken.providedBy(pf):
                 pf_c += 1
                 if name not in self.counter:
                     self.counter[name] = dict(anzahl=0,
                                               entwurf=0,
                                               gesendet=0,
                                               verarbeitung=0)
                 self.counter[name]['anzahl'] += len(pf)
                 for obj in pf.values():
                     state = IWorkflowState(obj).getState()
                     if state == 0:
                         self.counter[name]['entwurf'] += 1
                     elif state == 1:
                         self.counter[name]['gesendet'] += 1
                     elif state == 2:
                         self.counter[name]['verarbeitung'] += 1
     self.counter['ProductFolders'] = dict()
     self.counter['ProductFolders']['anzahl'] = pf_c
Esempio n. 4
0
 def update(self):
     self.counter = dict()
     inc = dict(anzahl=0, entwurf=0, gesendet=0, verarbeitung=0)
     hFB = getUtility(IHomeFolderManager).homeFolderBase
     self.counter['HomeFolder'] = inc
     self.counter['HomeFolder']['anzahl'] = len(hFB)
     pf_c = 0
     for homefolder in hFB.values():
         for name, pf in homefolder.items():
             if not IBroken.providedBy(pf):
                 pf_c += 1
                 if name not in self.counter:
                     self.counter[name] = dict(anzahl=0, entwurf=0, gesendet=0, verarbeitung=0) 
                 self.counter[name]['anzahl'] += len(pf)
                 for obj in pf.values():
                     state = IWorkflowState(obj).getState()
                     if state == 0:
                         self.counter[name]['entwurf'] += 1 
                     elif state == 1:
                         self.counter[name]['gesendet'] += 1 
                     elif state == 2:
                         self.counter[name]['verarbeitung'] += 1 
     self.counter['ProductFolders'] = dict() 
     self.counter['ProductFolders']['anzahl'] = pf_c
Esempio n. 5
0
def uncontained(object, container, name=None):  # pylint:disable=redefined-builtin
    """Clear the containment relationship between the *object* and
    the *container*.

    If we run this using the testing framework, we'll use `getEvents` to
    track the events generated:

    >>> from zope.component.eventtesting import getEvents
    >>> from zope.lifecycleevent.interfaces import IObjectModifiedEvent
    >>> from zope.lifecycleevent.interfaces import IObjectRemovedEvent

    We'll start by creating a container with an item:

    >>> class Item(Contained):
    ...     pass

    >>> item = Item()
    >>> container = {u'foo': item}
    >>> x, event = containedEvent(item, container, u'foo')
    >>> item.__parent__ is container
    1
    >>> item.__name__
    u'foo'

    Now we'll remove the item. It's parent and name are cleared:

    >>> uncontained(item, container, u'foo')
    >>> item.__parent__
    >>> item.__name__

    We now have a new removed event:

    >>> len(getEvents(IObjectRemovedEvent))
    1
    >>> event = getEvents(IObjectRemovedEvent)[-1]
    >>> event.object is item
    1
    >>> event.oldParent is container
    1
    >>> event.oldName
    u'foo'
    >>> event.newParent
    >>> event.newName

    As well as a modification event for the container:

    >>> len(getEvents(IObjectModifiedEvent))
    1
    >>> getEvents(IObjectModifiedEvent)[-1].object is container
    1

    Now if we call uncontained again:

    >>> uncontained(item, container, u'foo')

    We won't get any new events, because __parent__ and __name__ are None:

    >>> len(getEvents(IObjectRemovedEvent))
    1
    >>> len(getEvents(IObjectModifiedEvent))
    1

    But, if either the name or parent are not ``None`` and they are not the
    container and the old name, we'll get a modified event but not a removed
    event.

    >>> item.__parent__, item.__name__ = container, None
    >>> uncontained(item, container, u'foo')
    >>> len(getEvents(IObjectRemovedEvent))
    1
    >>> len(getEvents(IObjectModifiedEvent))
    2

    >>> item.__parent__, item.__name__ = None, u'bar'
    >>> uncontained(item, container, u'foo')
    >>> len(getEvents(IObjectRemovedEvent))
    1
    >>> len(getEvents(IObjectModifiedEvent))
    3

    If one tries to delete a Broken object, we allow them to do
    just that.

    >>> class Broken(object):
    ...     __Broken_state__ = {}
    >>> broken = Broken()
    >>> broken.__Broken_state__['__name__'] = u'bar'
    >>> broken.__Broken_state__['__parent__'] = container
    >>> container[u'bar'] = broken
    >>> uncontained(broken, container, u'bar')
    >>> len(getEvents(IObjectRemovedEvent))
    2

    """
    try:
        oldparent = object.__parent__
        oldname = object.__name__
    except AttributeError:
        # The old object doesn't implements IContained
        # Maybe we're converting old data:
        if hasattr(object, '__Broken_state__'):
            state = object.__Broken_state__
            oldparent = state['__parent__']
            oldname = state['__name__']
        else:
            if not fixing_up:
                raise
            oldparent = None
            oldname = None

    if oldparent is not container or oldname != name:
        if oldparent is not None or oldname is not None:
            notifyContainerModified(container)
        return

    event = ObjectRemovedEvent(object, oldparent, oldname)
    notify(event)

    if not IBroken.providedBy(object):
        object.__parent__ = None
        object.__name__ = None
    notifyContainerModified(container)
Esempio n. 6
0
def is_broken(resource):
    return IBroken.providedBy(resource)
Esempio n. 7
0
def is_broken(resource):
    return IBroken.providedBy(resource)
Esempio n. 8
0
File: util.py Progetto: ecreall/dace
def is_broken(resource):
    return isinstance(resource, BrokenWrapper) or \
           IBroken.providedBy(resource)
Esempio n. 9
0
def uncontained(object, container, name=None):
    """Clear the containment relationship between the `object` and
    the `container`.

    If we run this using the testing framework, we'll use `getEvents` to
    track the events generated:

    >>> from zope.component.eventtesting import getEvents
    >>> from zope.lifecycleevent.interfaces import IObjectModifiedEvent
    >>> from zope.lifecycleevent.interfaces import IObjectRemovedEvent

    We'll start by creating a container with an item:

    >>> class Item(Contained):
    ...     pass

    >>> item = Item()
    >>> container = {u'foo': item}
    >>> x, event = containedEvent(item, container, u'foo')
    >>> item.__parent__ is container
    1
    >>> item.__name__
    u'foo'

    Now we'll remove the item. It's parent and name are cleared:

    >>> uncontained(item, container, u'foo')
    >>> item.__parent__
    >>> item.__name__

    We now have a new removed event:

    >>> len(getEvents(IObjectRemovedEvent))
    1
    >>> event = getEvents(IObjectRemovedEvent)[-1]
    >>> event.object is item
    1
    >>> event.oldParent is container
    1
    >>> event.oldName
    u'foo'
    >>> event.newParent
    >>> event.newName

    As well as a modification event for the container:

    >>> len(getEvents(IObjectModifiedEvent))
    1
    >>> getEvents(IObjectModifiedEvent)[-1].object is container
    1

    Now if we call uncontained again:

    >>> uncontained(item, container, u'foo')

    We won't get any new events, because __parent__ and __name__ are None:

    >>> len(getEvents(IObjectRemovedEvent))
    1
    >>> len(getEvents(IObjectModifiedEvent))
    1

    But, if either the name or parent are not ``None`` and they are not the
    container and the old name, we'll get a modified event but not a removed
    event.

    >>> item.__parent__, item.__name__ = container, None
    >>> uncontained(item, container, u'foo')
    >>> len(getEvents(IObjectRemovedEvent))
    1
    >>> len(getEvents(IObjectModifiedEvent))
    2

    >>> item.__parent__, item.__name__ = None, u'bar'
    >>> uncontained(item, container, u'foo')
    >>> len(getEvents(IObjectRemovedEvent))
    1
    >>> len(getEvents(IObjectModifiedEvent))
    3

    If one tries to delete a Broken object, we allow them to do
    just that.

    >>> class Broken(object):
    ...     __Broken_state__ = {}
    >>> broken = Broken()
    >>> broken.__Broken_state__['__name__'] = u'bar'
    >>> broken.__Broken_state__['__parent__'] = container
    >>> container[u'bar'] = broken
    >>> uncontained(broken, container, u'bar')
    >>> len(getEvents(IObjectRemovedEvent))
    2

    """
    try:
        oldparent = object.__parent__
        oldname = object.__name__
    except AttributeError:
        # The old object doesn't implements IContained
        # Maybe we're converting old data:
        if hasattr(object, '__Broken_state__'):
            state = object.__Broken_state__
            oldparent = state['__parent__']
            oldname = state['__name__']
        else:
            if not fixing_up:
                raise
            oldparent = None
            oldname = None

    if oldparent is not container or oldname != name:
        if oldparent is not None or oldname is not None:
            notifyContainerModified(container)
        return

    event = ObjectRemovedEvent(object, oldparent, oldname)
    notify(event)

    if not IBroken.providedBy(object):
        object.__parent__ = None
        object.__name__ = None
    notifyContainerModified(container)
Esempio n. 10
0
def is_broken(resource):
    return isinstance(resource, BrokenWrapper) or \
           IBroken.providedBy(resource)