From 787a108deee8d7b54ce081d4f679c7c7aa25a9a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Benoi=CC=82t=20Pin?= Date: Sun, 7 Jul 2013 00:02:58 +0200 Subject: [PATCH] Ajout script pour parcourir l'arborescence et ajouter au catalogue. --- _zctl/rebuild-catalog.py | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 _zctl/rebuild-catalog.py diff --git a/_zctl/rebuild-catalog.py b/_zctl/rebuild-catalog.py new file mode 100644 index 0000000..e9d0395 --- /dev/null +++ b/_zctl/rebuild-catalog.py @@ -0,0 +1,62 @@ +from argparse import ArgumentParser +import os.path +from Acquisition import aq_base +from zope.site.hooks import setSite +from Products.CMFCore.CMFCatalogAware import CMFCatalogAware +import transaction + +# portal = app.realismc +# setSite(portal) +# ctool = portal.portal_catalog +# +# errorLog = open('/home/zope/checkcontents-errors.log', 'w') +count = 0 + +def checkContents(ob) : + global count + try : + print ob.absolute_url() + except Exception, e: + print >> errorLog, '%s/%s' % (ob.aq_parent.absolute_url(), ob.aq_base.id) + print >> errorLog, getattr(ob, 'portal_type', getattr(ob, 'meta_type', '')) + print >> errorLog, e + print >> errorLog + + if isinstance(aq_base(ob), CMFCatalogAware) : + assert ob._getCatalogTool() + try : + ctool.indexObject(ob) + count = count + 1 + if count % 1000 == 0 : + transaction.commit() + print count, 'commit.' + except Exception, e: + print >> errorLog, '%s/%s' % (ob.aq_parent.absolute_url(), ob.aq_base.id) + print >> errorLog, e + + if hasattr(aq_base(ob), 'objectItems') : + obs = ob.objectItems() + for k, v in obs : + checkContents(v) + + +parser = ArgumentParser(description="Deflate blobs backup set.") +parser.add_argument('portal_path') +parser.add_argument('--error-log', help='Error log file. Default: ~/catalog-rebuild-error.log', + default='~/catalog-rebuild-error.log', required=False, dest='errorLogPath') + +args = parser.parse_args() +portal = app.unrestrictedTraverse(args.portal_path) +setSite(portal) +ctool = portal.portal_catalog +errorLogPath = os.path.expanduser(args.errorLogPath) +errorLog = open(errorLogPath, 'w') + +try : + checkContents(portal) + transaction.commit() + print count + print 'Done.' +finally : + errorLog.close() + -- 2.20.1