29a948bfb6aa28ebe38717655f5d21f0cf8fef24
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
10 def checkContents(ob
) :
13 print ob
.absolute_url()
15 print >> errorLog
, '%s/%s' % (ob
.aq_parent
.absolute_url(), ob
.aq_base
.id)
16 print >> errorLog
, getattr(ob
, 'portal_type', getattr(ob
, 'meta_type', ''))
20 if isinstance(aq_base(ob
), CMFCatalogAware
) :
21 assert ob
._getCatalogTool
()
25 if count
% 1000 == 0 :
27 print count
, 'commit.'
29 print >> errorLog
, '%s/%s' % (ob
.aq_parent
.absolute_url(), ob
.aq_base
.id)
32 if hasattr(aq_base(ob
), 'objectItems') :
33 obs
= ob
.objectItems()
38 parser
= ArgumentParser(description
="Rebuild entire catalog by walking contents tree.")
39 parser
.add_argument('portal_path')
40 parser
.add_argument('--error-log', help='Error log file. Default: ~/catalog-rebuild-error.log',
41 default
='~/catalog-rebuild-error.log', required
=False, dest
='errorLogPath')
43 args
= parser
.parse_args()
44 portal
= app
.unrestrictedTraverse(args
.portal_path
)
46 ctool
= portal
.portal_catalog
47 errorLogPath
= os
.path
.expanduser(args
.errorLogPath
)
48 errorLog
= open(errorLogPath
, 'w')