# Copyright (c) 2010 gocept gmbh & co. kg
# See also LICENSE.txt

import zeit.brightcove.interfaces
import zeit.cms.generation
import zope.component


def update(root):
    # Remove the brightcove repository from ZODB
    repository = zope.component.queryUtility(
        zeit.brightcove.interfaces.IRepository)
    if repository is not None:
        site_manager = zope.component.getSiteManager()
        site_manager.unregisterUtility(
            repository,
            zeit.brightcove.interfaces.IRepository)
        del repository.__parent__[repository.__name__]

def evolve(context):
    zeit.cms.generation.do_evolve(context, update)


@@ -59,16 +59,59 @@
 SE.txt%0A%0A
+import BTrees%0Aimport persistent%0Aimport sys%0A
 import z
@@ -189,27 +189,1174 @@
 ent%0A
-%0A%0Adef update(root):
+import zope.container.contained%0A%0A%0Aclass Repository(persistent.Persistent,%0A                 zope.container.contained.Contained):%0A    # Stub so the generation can remove the objects properly%0A%0A    zope.interface.implements(zeit.brightcove.interfaces.IRepository)%0A%0A    def __init__(self):%0A        self._data = BTrees.family32.OO.BTree()%0A%0A    def __getitem__(self, key):%0A        return self._data%5Bkey%5D%0A%0A    def __setitem__(self, key, obj):%0A        self._data%5Bkey%5D = obj%0A%0A    def get(self, key):%0A        return self._data.get(key)%0A%0A    def __iter__(self):%0A        return iter(self._data)%0A%0A    def keys(self):%0A        return self._data.keys()%0A%0A    def values(self):%0A        return self._data.values()%0A%0A    def items(self):%0A        return self._data.items()%0A%0A%0Aclass Content(persistent.Persistent,%0A            zope.container.contained.Contained):%0A    # Stub so the generation can remove the objects properly%0A    pass%0A%0AVideo = Playlist = Content%0A%0A%0Adef update(root):%0A    # Fake the old locations of persistent objects%0A    from zeit.brightcove.generation import evolve2%0A    sys.modules%5B'zeit.brightcove.repository'%5D = evolve2%0A    sys.modules%5B'zeit.brightcove.content'%5D = evolve2
 %0A   
@@ -1400,17 +1400,31 @@
 rom ZODB
+.
 %0A
+    try:%0A    
     repo
@@ -1461,32 +1461,36 @@
 tility(%0A        
+   
+ 
 zeit.brightcove.
@@ -1509,24 +1509,28 @@
 Repository)%0A
+    
     if repos
@@ -1548,32 +1548,36 @@
 t None:%0A        
+ 
+   
 site_manager = z
@@ -1607,32 +1607,36 @@
 nager()%0A        
+  
+  
 site_manager.unr
@@ -1643,32 +1643,36 @@
 egisterUtility(%0A
+    
             repo
@@ -1683,32 +1683,36 @@
 ry,%0A            
+    
 zeit.brightcove.
@@ -1747,12 +1747,22 @@
     
+ 
+   
 del 
+root%5B'
 repo
@@ -1771,40 +1771,140 @@
 tory
-.__parent__%5Brepository.__name__%5D
+-brightcove'%5D%0A    finally:%0A        del sys.modules%5B'zeit.brightcove.repository'%5D%0A        del sys.modules%5B'zeit.brightcove.content'%5D%0A
 %0A%0Ade

fix evolve2: remove the brightcove repository and contents