equal
deleted
inserted
replaced
10 # FOR A PARTICULAR PURPOSE. |
10 # FOR A PARTICULAR PURPOSE. |
11 # |
11 # |
12 |
12 |
13 __docformat__ = 'restructuredtext' |
13 __docformat__ = 'restructuredtext' |
14 |
14 |
15 |
|
16 # import standard library |
|
17 import transaction |
15 import transaction |
18 |
16 from ZODB.interfaces import IBroken |
19 # import interfaces |
|
20 from hypatia.interfaces import ICatalog |
17 from hypatia.interfaces import ICatalog |
|
18 from zope.interface import Interface |
21 from zope.intid.interfaces import IIntIds |
19 from zope.intid.interfaces import IIntIds |
22 |
20 |
23 # import packages |
|
24 from pyams_utils.container import find_objects_providing |
21 from pyams_utils.container import find_objects_providing |
25 from pyams_utils.registry import set_local_registry, get_utility |
22 from pyams_utils.registry import set_local_registry, get_utility |
26 from pyams_utils.site import site_factory |
23 from pyams_utils.site import site_factory |
27 from zope.interface import Interface |
|
28 |
24 |
29 |
25 |
30 def site_index(request): |
26 def site_index(request): |
31 """Index all site contents in internal catalog""" |
27 """Index all site contents in internal catalog""" |
32 application = site_factory(request) |
28 application = site_factory(request) |
36 catalog = get_utility(ICatalog) |
32 catalog = get_utility(ICatalog) |
37 catalog.reset() |
33 catalog.reset() |
38 transaction.savepoint() |
34 transaction.savepoint() |
39 intids = get_utility(IIntIds) |
35 intids = get_utility(IIntIds) |
40 for index, document in enumerate(find_objects_providing(application, Interface)): |
36 for index, document in enumerate(find_objects_providing(application, Interface)): |
41 print("Indexing: {0!r}".format(document)) |
37 if IBroken.providedBy(document): |
42 catalog.reindex_doc(intids.register(document), document) |
38 print("Skipping broken object: {0!r}".format(document)) |
43 if not index % 100: |
39 else: |
44 transaction.savepoint() |
40 print("Indexing: {0!r}".format(document)) |
|
41 catalog.reindex_doc(intids.register(document), document) |
|
42 if not index % 100: |
|
43 transaction.savepoint() |
45 finally: |
44 finally: |
46 set_local_registry(None) |
45 set_local_registry(None) |
47 transaction.commit() |
46 transaction.commit() |
48 return application |
47 return application |