Commit 0ecd2953 authored by Andreas Jung's avatar Andreas Jung

- added utilities/reindex_catalog.py to perform ZCatalog maintenance

       operations from the command line (through zopectl)
parent 6ab94292
...@@ -26,6 +26,9 @@ Zope Changes ...@@ -26,6 +26,9 @@ Zope Changes
Features added Features added
- added utilities/reindex_catalog.py to perform ZCatalog maintenance
operations from the command line (through zopectl)
- RESPONSE.setBody and RESPONSE.setStatus now accept lock - RESPONSE.setBody and RESPONSE.setStatus now accept lock
parameters in the same way as RESPONSE.redirect. These prevent parameters in the same way as RESPONSE.redirect. These prevent
further calls to the methods from overwriting the previous value. further calls to the methods from overwriting the previous value.
......
...@@ -1131,7 +1131,7 @@ distutils.core.setup( ...@@ -1131,7 +1131,7 @@ distutils.core.setup(
scripts=["utilities/mkzeoinstance.py", "utilities/mkzopeinstance.py", scripts=["utilities/mkzeoinstance.py", "utilities/mkzopeinstance.py",
"utilities/check_catalog.py", "utilities/load_site.py", "utilities/check_catalog.py", "utilities/load_site.py",
"utilities/requestprofiler.py", "utilities/zpasswd.py", "utilities/requestprofiler.py", "utilities/zpasswd.py",
"utilities/copyzopeskel.py", "utilities/copyzopeskel.py", "utilities/reindex_catalog.py",
"utilities/compilezpy.py", "utilities/decompilezpy.py", "utilities/compilezpy.py", "utilities/decompilezpy.py",
"test.py"], "test.py"],
distclass=ZopeDistribution, distclass=ZopeDistribution,
......
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""
A utility to perform external reindex operations for ZCatalogs
Usage:
zopectl run reindex_catalog.py [options]
Use --help to get a list of all options.
Author: Andreas Jung (andreas@andreas-jung.com)
$Id$
"""
import sys
from optparse import OptionParser
from Products.ZCatalog.ProgressHandler import StdoutHandler
def path2catalog(path):
""" lookup catalog by path """
catalog = app.restrictedTraverse(path, None)
if not catalog:
raise ValueError('No catalog found at %s' % path)
return catalog
def getHandler(options):
""" return a progress handler """
if options.silent:
return None
else:
return StdoutHandler(options.steps)
def listIndexes(options, args):
""" print a list of all indexes to stdout """
catalog = path2catalog(options.catalog)
indexes = catalog._catalog.indexes
print 'Listing of all indexes at %s' % options.catalog
print
for id, idx in indexes.items():
print '%-20s %-50s %d' % (id, idx.meta_type, idx.numObjects())
def reindexIndexes(optioons, args):
""" reindex given list of indexes """
catalog = path2catalog(options.catalog)
handler = getHandler(options)
for id in args:
print 'Reindexing index %s at %s' % (id, options.catalog)
catalog.reindexIndex(id, None, handler)
get_transaction().commit()
def refreshMetadata(options, args):
""" reindex metadata """
catalog = path2catalog(options.catalog)
handler = getHandler(options)
print 'Refresh metadata at %s' % options.catalog
catalog.refreshMetadata(handler)
get_transaction().commit()
def reindexAll(options, args):
""" reindex complete catalog """
catalog = path2catalog(options.catalog)
handler = getHandler(options)
print 'Reindexing complete ZCatalog at %s' % options.catalog
catalog.refreshCatalog(options.clearCatalog, handler)
get_transaction().commit()
if __name__ == '__main__':
parser = OptionParser()
parser.add_option('-c', '--catalog', dest='catalog',
help='path to ZCatalog')
parser.add_option('-i', '--indexes', action="store_true", dest="listIndexes",
help='list all indexes')
parser.add_option('-C', '--clear', action="store_true", dest="clearCatalog", default=False,
help='clear catalog before reindexing the complete catalog (--all only)')
parser.add_option('-a', '--all', action="store_true", dest="reindexAll",
help='reindex the complete catalog and update all metadata')
parser.add_option('-r', '--reindex', action="store_true", dest="reindexIndexes",
help='reindex specified indexes')
parser.add_option('-m', '--metadata', action="store_true", dest="refreshMetadata",
help='refresh all metadata')
parser.add_option('-n', '--steps', dest="steps", default=100, type="int",
help='log progress every N objects')
parser.add_option('-s', '--silent', action="store_true", dest="silent", default=False,
help='do not log reindexing progress to stdout')
options,args = parser.parse_args()
if options.listIndexes: listIndexes(options, args)
if options.reindexIndexes: reindexIndexes(options, args)
if options.refreshMetadata: refreshMetadata(options, args)
if options.reindexAll: reindexAll(options, args)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment