coup de plumeau à l'aide de jslint.
[Plinn.git] / _zctl / rebuild-catalog.py
1 from argparse import ArgumentParser
2 import os.path
3 from Acquisition import aq_base
4 from zope.site.hooks import setSite
5 from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
6 import transaction
7
8 # portal = app.realismc
9 # setSite(portal)
10 # ctool = portal.portal_catalog
11 #
12 # errorLog = open('/home/zope/checkcontents-errors.log', 'w')
13 count = 0
14
15 def checkContents(ob) :
16 global count
17 try :
18 print ob.absolute_url()
19 except Exception, e:
20 print >> errorLog, '%s/%s' % (ob.aq_parent.absolute_url(), ob.aq_base.id)
21 print >> errorLog, getattr(ob, 'portal_type', getattr(ob, 'meta_type', ''))
22 print >> errorLog, e
23 print >> errorLog
24
25 if isinstance(aq_base(ob), CMFCatalogAware) :
26 assert ob._getCatalogTool()
27 try :
28 ctool.indexObject(ob)
29 count = count + 1
30 if count % 1000 == 0 :
31 transaction.commit()
32 print count, 'commit.'
33 except Exception, e:
34 print >> errorLog, '%s/%s' % (ob.aq_parent.absolute_url(), ob.aq_base.id)
35 print >> errorLog, e
36
37 if hasattr(aq_base(ob), 'objectItems') :
38 obs = ob.objectItems()
39 for k, v in obs :
40 checkContents(v)
41
42
43 parser = ArgumentParser(description="Deflate blobs backup set.")
44 parser.add_argument('portal_path')
45 parser.add_argument('--error-log', help='Error log file. Default: ~/catalog-rebuild-error.log',
46 default='~/catalog-rebuild-error.log', required=False, dest='errorLogPath')
47
48 args = parser.parse_args()
49 portal = app.unrestrictedTraverse(args.portal_path)
50 setSite(portal)
51 ctool = portal.portal_catalog
52 errorLogPath = os.path.expanduser(args.errorLogPath)
53 errorLog = open(errorLogPath, 'w')
54
55 try :
56 checkContents(portal)
57 transaction.commit()
58 print count
59 print 'Done.'
60 finally :
61 errorLog.close()
62