--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/features/catalog/__init__.py Mon Nov 05 11:18:34 2018 +0100
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+
+__docformat__ = 'restructuredtext'
+
+import transaction
+from ZODB.interfaces import IBroken
+from hypatia.interfaces import ICatalog
+from zope.interface import Interface
+from zope.intid import IIntIds
+
+from pyams_utils.container import find_objects_providing
+from pyams_utils.registry import get_utility, set_local_registry
+from pyams_utils.site import site_factory
+
+
+def site_index(request):
+ """Index all site contents in internal catalog"""
+ application = site_factory(request)
+ if application is not None:
+ try:
+ set_local_registry(application.getSiteManager())
+ catalog = get_utility(ICatalog)
+ catalog.reset()
+ transaction.savepoint()
+ intids = get_utility(IIntIds)
+ for index, document in enumerate(find_objects_providing(application, Interface)):
+ if IBroken.providedBy(document):
+ print("Skipping broken object: {0!r}".format(document))
+ else:
+ print("Indexing: {0!r}".format(document))
+ catalog.reindex_doc(intids.register(document), document)
+ if not index % 100:
+ transaction.savepoint()
+ finally:
+ set_local_registry(None)
+ transaction.commit()
+ return application
--- a/src/pyams_content/scripts/index.py Mon Nov 05 11:17:52 2018 +0100
+++ b/src/pyams_content/scripts/index.py Mon Nov 05 11:18:34 2018 +0100
@@ -12,17 +12,13 @@
__docformat__ = 'restructuredtext'
-
-# import standard library
import argparse
import sys
import textwrap
-# import interfaces
+from pyramid.paster import bootstrap
-# import packages
-from pyams_content.site import site_index
-from pyramid.paster import bootstrap
+from pyams_content.features.catalog import site_index
def index_site():
--- a/src/pyams_content/site.py Mon Nov 05 11:17:52 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-#
-# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-
-__docformat__ = 'restructuredtext'
-
-import transaction
-from ZODB.interfaces import IBroken
-from hypatia.interfaces import ICatalog
-from zope.interface import Interface
-from zope.intid.interfaces import IIntIds
-
-from pyams_utils.container import find_objects_providing
-from pyams_utils.registry import set_local_registry, get_utility
-from pyams_utils.site import site_factory
-
-
-def site_index(request):
- """Index all site contents in internal catalog"""
- application = site_factory(request)
- if application is not None:
- try:
- set_local_registry(application.getSiteManager())
- catalog = get_utility(ICatalog)
- catalog.reset()
- transaction.savepoint()
- intids = get_utility(IIntIds)
- for index, document in enumerate(find_objects_providing(application, Interface)):
- if IBroken.providedBy(document):
- print("Skipping broken object: {0!r}".format(document))
- else:
- print("Indexing: {0!r}".format(document))
- catalog.reindex_doc(intids.register(document), document)
- if not index % 100:
- transaction.savepoint()
- finally:
- set_local_registry(None)
- transaction.commit()
- return application