Back to index

plone3  3.1.7
Functions | Variables
CMFPlone.Extensions.cleanup Namespace Reference

Functions

def cleanUpCatalog
def removeUnreachable

Variables

list remove_unreachable = sys.argv[2:]
tuple catalog = app.unrestrictedTraverse(sys.argv[1])

Detailed Description

$Id: cleanup.py 10017 2006-06-09 20:53:36Z hannosch $

Function Documentation

def CMFPlone.Extensions.cleanup.cleanUpCatalog (   catalog,
  out 
)

Definition at line 8 of file cleanup.py.

00008 
00009 def cleanUpCatalog(catalog, out):
00010     _cat = catalog._catalog
00011     print >> out, "calculating inconsistencies on metadata trees..."
00012     data_rids = Set(_cat.data.keys())
00013     path_rids = Set(_cat.paths.keys())
00014     uids_rids = Set(_cat.uids.values())
00015 
00016     good_rids = data_rids & path_rids & uids_rids
00017     bad_rids = (data_rids | path_rids | uids_rids) - good_rids
00018     print >> out, "%s inconsistent entries detected" % len(bad_rids)
00019     pf_rids = Set()
00020     bad_paths = Set()
00021     for rid, path in _cat.paths.items():
00022         if "portal_factory/" in path:
00023             pf_rids.add(rid)
00024             bad_paths.add(path)
00025     for path, rid in _cat.uids.items():
00026         if "portal_factory/" in path:
00027             pf_rids.add(rid)
00028             bad_paths.add(path)
00029         if rid in bad_rids:
00030             bad_paths.add(path)
00031     pathIndex = _cat.getIndex('path')
00032     p_args = dict(query='portal_factory', level=-1)
00033     pf_rids |= Set(pathIndex._apply_index(dict(path=p_args))[0].keys())
00034     print >> out, "%s portal_factory entries detected" % len(pf_rids)
00035     bad_rids |= pf_rids
00036     print >> out, "cleaning up uids..."
00037     for path in bad_paths:
00038         try:
00039             del _cat.uids[path]
00040         except KeyError:
00041             pass
00042     print >> out, "cleaning up data and paths and indexes..."
00043     indexes = [_cat.getIndex(name) for name in _cat.indexes.keys()]
00044     for rid in bad_rids:
00045         try:
00046             del _cat.paths[rid]
00047         except KeyError:
00048             pass
00049         try:
00050             del _cat.data[rid]
00051         except KeyError:
00052             pass
00053         for index in indexes:
00054             if hasattr(index, 'unindex_object'):
00055                 index.unindex_object(rid)
00056     print >> out, "Done"

Here is the call graph for this function:

def CMFPlone.Extensions.cleanup.removeUnreachable (   catalog,
  out 
)

Definition at line 57 of file cleanup.py.

00057 
00058 def removeUnreachable(catalog, out):
00059     _cat = catalog._catalog
00060     count = 0
00061     print >> out, "removing unreachable entries in the catalog..."
00062     for path in _cat.uids.keys():
00063         if not catalog.aq_parent.unrestrictedTraverse(path, None):
00064             _cat.uncatalogObject(path)
00065             count +=1
00066     print >> out, "%s entries removed" % count


Variable Documentation

tuple CMFPlone.Extensions.cleanup.catalog = app.unrestrictedTraverse(sys.argv[1])

Definition at line 71 of file cleanup.py.

Definition at line 70 of file cleanup.py.