Created
June 14, 2013 05:04
-
-
Save daniel-garcia/5779577 to your computer and use it in GitHub Desktop.
attempt to coninue a zencatalog --createcatalog --forceindex, with a new --continueindex option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: Products/ZenUtils/zencatalog.py | |
=================================================================== | |
--- Products/ZenUtils/zencatalog.py (revision 73688) | |
+++ 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,19 @@ | |
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) | |
+ | |
+ paths = set(brain.getPath() for brain in catalog()) | |
+ def is_new(ob): | |
+ try: | |
+ path = ob.getPrimaryUrlPath() | |
+ return not (path in paths) | |
+ except Exception: | |
+ return True | |
+ | |
def recurse(obj): | |
if _reconnect[0]: | |
log.info('Reconnected.') | |
@@ -233,7 +246,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 +267,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