[Zope] finding orphaned Product objects

Max M maxm at mxm.dk
Wed Mar 10 05:15:20 EST 2004


Fred Yankowski wrote:

 > I want to clean up a Zope instance to remove some installed products
 > that are no longer needed or even available in the filesystem any
 > more.  I've got an idea about how to do that and I'm looking for
 > feedback about any problems or shortcomings.


I think my approach would to find all the legal meta_types, and then 
traverse the whole tree, and see if the products had any of the legal 
meta types (untested):

from cStringIO import StringIO
import Products

def batch(self):
     "A batch processor script"
     out = StringIO()
     pr = out.write
     # legal types
     checker = {}
     for mt in Products.meta_types:
         checker[mt] = 1
     # Find the objects
     objects = self.ZopeFind(self, search_sub=1)
     for path, obj in objects:
         if not checker.get(obj.meta_type, 0)
             parent = obj.aq_parent
             try:
                 pr('Deleting object at: %s of type:\n' % 
('/'.join(obj.getPhysicalPath(), obj.meta_type)))
                 parent.manage_delObjects(ids=obj.getId())
             except:
                 pr('There was a failure\n')

     return out.getvalue()


regards Max M



More information about the Zope mailing list