1 from argparse
import ArgumentParser
3 from Acquisition
import aq_base
4 from zope
.site
.hooks
import setSite
5 from Products
.CMFCore
.CMFCatalogAware
import CMFCatalogAware
11 def checkContents(ob
) :
15 print ob
.absolute_url()
17 print >> errorLog
, '%s/%s' % (ob
.aq_parent
.absolute_url(), ob
.aq_base
.id)
18 print >> errorLog
, getattr(ob
, 'portal_type', getattr(ob
, 'meta_type', ''))
22 if isinstance(aq_base(ob
), CMFCatalogAware
) :
23 ctool
= ob
._getCatalogTool
()
28 if count
% 1000 == 0 :
30 print count
, 'commit.'
32 print >> errorLog
, '%s/%s' % (ob
.aq_parent
.absolute_url(), ob
.aq_base
.id)
35 if hasattr(aq_base(ob
), 'objectItems') :
36 obs
= ob
.objectItems()
41 def indexMemberdata(portal
) :
42 mtool
= portal
.portal_membership
43 ctool
= portal
.portal_catalog
44 for m
in mtool
.getOtherMembers([]) :
48 portal
= app
.unrestrictedTraverse(path
)
50 errorLogPath
= os
.path
.expanduser(args
.errorLogPath
)
52 errorLog
= open(errorLogPath
, 'w')
57 indexMemberdata(portal
)
66 if __name__
== '__main__':
67 parser
= ArgumentParser(description
="Rebuild entire catalog by walking contents tree.")
68 parser
.add_argument('portal_path')
69 parser
.add_argument('--error-log', help='Error log file. Default: ~/catalog-rebuild-error.log',
70 default
='~/catalog-rebuild-error.log', required
=False, dest
='errorLogPath')
72 args
= parser
.parse_args()
73 main(args
.portal_path
)