Skip to content

Instantly share code, notes, and snippets.

@daniel-garcia
Created June 14, 2013 16:02
Show Gist options
  • Save daniel-garcia/5783085 to your computer and use it in GitHub Desktop.
Save daniel-garcia/5783085 to your computer and use it in GitHub Desktop.
Index: Products/ZenUtils/zencatalog.py
===================================================================
--- Products/ZenUtils/zencatalog.py (revision 74143)
+++ Products/ZenUtils/zencatalog.py (working copy)
@@ -115,6 +115,10 @@
action="store_true",
default=False,
help="Create global catalog and populate it")
+ self.parser.add_option("--continueindex",
+ action="store_true",
+ default=False,
+ help="Attempt to continue a --createcatalog")
self.parser.add_option("--forceindex",
action="store_true",
default=False,
@@ -178,10 +182,24 @@
factory.create(zport)
catalog = self._getCatalog(zport)
transaction.commit()
- else:
- log.info('Global catalog already exists. Run with --forceindex to drop and recreate catalog')
+ elif not self.options.continueindex:
+ log.info('Global catalog already exists. Run with --forceindex to drop and recreate catalog or --continueindex to continue rebuilding the catalog')
return defer.succeed(None)
+
+ # create a set of paths for all the objects already in the global catalog
+ paths = set(zport.global_catalog._catalog.uids)
+ def is_new(ob):
+ """
+ Return True if the object was not in the global catalog
+ on start up; False otherwise.
+ """
+ try:
+ path = "/".join(ob.getPhysicalPath())
+ return not (path in paths)
+ except Exception:
+ return True
+
def recurse(obj):
if _reconnect[0]:
log.info('Reconnected.')
@@ -233,7 +251,8 @@
if hasattr(ob, 'index_object'):
ob.index_object()
catalog.catalog_object(ob)
- log.debug('Catalogued object %s' % ob.absolute_url_path())
+ if log.isEnabledFor(logging.DEBUG):
+ log.debug('Catalogued object %s' % ob.absolute_url_path())
# Count of catalogued objects. Because the nested func has no access to
# this scope, have to make it a mutable
@@ -253,7 +272,8 @@
try:
for ob in filter(None, c):
try:
- catalog_object(ob)
+ if is_new(ob):
+ catalog_object(ob)
except Exception:
log.info("Error indexing object %r. Skipping." % ob)
transaction.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment