import sys from string import join def isGlobalRegistryCorrupt(self): jar = self._p_jar zg = jar.root()['ZGlobals'] try: keys = list(zg.keys()) except: return 'Corrupt.' return 'Clean.' def cleanGlobals(self, RESPONSE=None): # Recreates the global registry. jar = self._p_jar root = jar.root() from BTree import BTree root['ZGlobals'] = BTree() products = self.Control_Panel.Products messages = ['Created a new global registry.'] for prod in products.objectValues(): messages.append('Examining product %s...' % prod.id) items = list(prod.objectItems()) idx = 0 finished = [] while (idx < len(items)): name, ob = items[idx] base = getattr(ob, 'aq_base', ob) if base in finished: idx = idx + 1 continue finished.append(base) try: if hasattr(ob, '_register') and hasattr(ob, '_zclass_'): ob._register() messages.append( 'Successfully registered "%s".' % name) except: t, v = sys.exc_info()[:2] messages.append( 'Failed on "%s": %s, %s.' % (name, t, v)) # Include subobjects. try: if hasattr(ob, 'objectItems'): m = list(ob.objectItems()) items.extend(m) except: pass try: m = list(ob.propertysheets.methods.objectItems()) items.extend(m) except: pass idx = idx + 1 if RESPONSE is not None: RESPONSE.setHeader('Content-type', 'text/plain') return join(messages, '\n')