annotate MoinMoin/events/xapian_index.py @ 6076:f4ec84967c27

add colon to make log_attempt even more parseable
author 'Karl O. Pinc' <kop@meme.com>
date Mon, 15 Sep 2014 22:10:45 -0500
parents d25574af97eb
children
rev   line source
2388
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2 """
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
3 MoinMoin - (re)building of Xapian indices
2490
111868e5cb21 Regenerate xapian index on added attachment, fix PageDeletedEvent, fix header
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2390
diff changeset
4
111868e5cb21 Regenerate xapian index on added attachment, fix PageDeletedEvent, fix header
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2390
diff changeset
5 @copyright: 2007 MoinMoin:KarolNowak
111868e5cb21 Regenerate xapian index on added attachment, fix PageDeletedEvent, fix header
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2390
diff changeset
6 @license: GNU GPL, see COPYING for details.
2388
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
7 """
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
8
2388
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
9 import MoinMoin.events as ev
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
10
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
11
5022
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
12 def _get_index(request):
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
13 try:
5044
f5f3d7348564 Xapian2009: Class Xapian.indexing.Index is renamed to XapianIndex. _check_version() was removed, xapian binding check is done by xappy. XapianSearch was moved to Xapian.search. Log message is shown if xapian version is too old.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 5022
diff changeset
14 from MoinMoin.search.Xapian import XapianIndex
f5f3d7348564 Xapian2009: Class Xapian.indexing.Index is renamed to XapianIndex. _check_version() was removed, xapian binding check is done by xappy. XapianSearch was moved to Xapian.search. Log message is shown if xapian version is too old.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 5022
diff changeset
15 return XapianIndex(request)
5022
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
16 except ImportError:
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
17 pass
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
18
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
19
2388
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
20 def handle_renamed(event):
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
21 """Updates Xapian index when a page changes its name"""
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
22
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
23 request = event.request
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
24
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
25 if request.cfg.xapian_search:
5022
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
26 index = _get_index(request)
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
27 if index and index.exists():
5276
195db0fdbb80 Fixed and cleaned up Xapian based search (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5044
diff changeset
28 index.update_item(event.old_page.page_name, now=False)
195db0fdbb80 Fixed and cleaned up Xapian based search (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5044
diff changeset
29 index.update_item(event.page.page_name)
2388
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
30
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
31
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
32 def handle_copied(event):
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
33 """Updates Xapian index when a page is copied"""
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
34
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
35 request = event.request
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
36
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
37 if request.cfg.xapian_search:
5022
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
38 index = _get_index(request)
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
39 if index and index.exists():
5276
195db0fdbb80 Fixed and cleaned up Xapian based search (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5044
diff changeset
40 index.update_item(event.page.page_name)
2388
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
41
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
42
5276
195db0fdbb80 Fixed and cleaned up Xapian based search (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5044
diff changeset
43 def handle_changed(event):
2388
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
44 """Updates Xapian index when a page is changed"""
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
45
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
46 request = event.request
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
47
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
48 if request.cfg.xapian_search:
5022
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
49 index = _get_index(request)
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
50 if index and index.exists():
5276
195db0fdbb80 Fixed and cleaned up Xapian based search (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5044
diff changeset
51 index.update_item(event.page.page_name)
2388
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
52
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
53
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
54 def handle_deleted(event):
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
55 """Updates Xapian index when a page is deleted"""
2490
111868e5cb21 Regenerate xapian index on added attachment, fix PageDeletedEvent, fix header
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2390
diff changeset
56 event = ev.PageChangedEvent(event.request, event.page, event.comment)
5276
195db0fdbb80 Fixed and cleaned up Xapian based search (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5044
diff changeset
57 handle_changed(event)
2390
4ac1c1635aba Remove a stray debugging print.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2388
diff changeset
58
2388
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
59
5279
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5276
diff changeset
60 def handle_attachment_change(event):
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5276
diff changeset
61 """Updates Xapian index when attachment is added or removed"""
2490
111868e5cb21 Regenerate xapian index on added attachment, fix PageDeletedEvent, fix header
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2390
diff changeset
62
111868e5cb21 Regenerate xapian index on added attachment, fix PageDeletedEvent, fix header
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2390
diff changeset
63 request = event.request
111868e5cb21 Regenerate xapian index on added attachment, fix PageDeletedEvent, fix header
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2390
diff changeset
64
111868e5cb21 Regenerate xapian index on added attachment, fix PageDeletedEvent, fix header
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2390
diff changeset
65 if request.cfg.xapian_search:
5022
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
66 index = _get_index(request)
a93283d1f827 Xapian2009: XAPIAN_MIN_VERSION is 1.0.6, events.xapian_index doesn't raise an exception when old xapian is installed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4573
diff changeset
67 if index and index.exists():
5276
195db0fdbb80 Fixed and cleaned up Xapian based search (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5044
diff changeset
68 index.update_item(event.pagename, event.filename)
2490
111868e5cb21 Regenerate xapian index on added attachment, fix PageDeletedEvent, fix header
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2390
diff changeset
69
111868e5cb21 Regenerate xapian index on added attachment, fix PageDeletedEvent, fix header
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2390
diff changeset
70
2388
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
71 def handle(event):
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
72 if isinstance(event, ev.PageRenamedEvent):
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
73 handle_renamed(event)
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
74 elif isinstance(event, ev.PageCopiedEvent):
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
75 handle_copied(event)
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
76 elif isinstance(event, (ev.PageChangedEvent, ev.TrivialPageChangedEvent)):
2388
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
77 handle_changed(event)
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
78 elif isinstance(event, ev.PageDeletedEvent):
ca82098b3e5f Add a file forgotten from the previous commits...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
79 handle_deleted(event)
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
80 elif isinstance(event, (ev.FileAttachedEvent, ev.FileRemovedEvent)):
5279
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5276
diff changeset
81 handle_attachment_change(event)
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5276
diff changeset
82