annotate MoinMoin/events/__init__.py @ 2145:f153b3155240

Send notifications about creation of users to Superusers with JID set.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 17 Jun 2007 02:44:13 +0200
parents b39379ab47d3
children cf4c4a3d6085
rev   line source
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2 """
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
3 MoinMoin - event (notification) framework
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
4
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
5 This code abstracts event handling in MoinMoin,
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
6 currently for notifications. It implements the observer pattern.
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
7
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
8 @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
9 @license: GNU GPL, see COPYING for details.
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
10 """
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
11
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
12 from MoinMoin import wikiutil
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
13 from MoinMoin.util import pysupport
2073
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
14 from MoinMoin.wikiutil import PluginAttributeError
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
15
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
16
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
17 # A list of available event handlers
2095
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
18 _event_handlers = None
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
19
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
20 # Create a list of extension actions from the package directory
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
21 modules = pysupport.getPackageModules(__file__)
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
22
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
23
2091
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
24 class Event:
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
25 """A class handling information common to all events."""
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
26 def __init__(self, request):
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
27 self.request = request
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
28
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
29
2091
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
30 class PageEvent(Event):
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
31 """An event related to a page change"""
2094
9ee68c8b409b Style fixes as suggested by Thomas.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
32 def __init__(self, request):
9ee68c8b409b Style fixes as suggested by Thomas.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
33 Event.__init__(self, request)
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
34
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
35
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
36 class PageChangedEvent(PageEvent):
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
37 def __init__(self, request, page, comment, trivial):
2094
9ee68c8b409b Style fixes as suggested by Thomas.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
38 PageEvent.__init__(self, request)
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
39 self.page = page
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
40 self.comment = comment
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
41 self.trivial = trivial
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
42
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
43
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
44 class PageRenamedEvent(PageEvent):
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
45 pass
2109
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
46
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
47
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
48 class PageDeletedEvent(PageEvent):
2109
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
49 def __init__(self, request, page, comment):
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
50 PageEvent.__init__(self, request)
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
51 self.request = request
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
52 self.page = page
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
53 self.comment = comment
2106
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
54
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
55
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
56 class FileAttachedEvent(PageEvent):
2106
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
57 def __init__(self, request, pagename, attachment_name, size):
2107
645bbc7fe2b5 Add forgotten invocation of parent constructor.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2106
diff changeset
58 PageEvent.__init__(self, request)
2106
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
59 self.request = request
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
60 self.pagename = pagename
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
61 self.attachment_name = attachment_name
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
62 self.size = size
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
63
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
64
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
65 class PageRevertedEvent(PageEvent):
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
66 def __init__(self, request, pagename, previous, current):
2094
9ee68c8b409b Style fixes as suggested by Thomas.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
67 PageEvent.__init__(self, request)
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
68 self.pagename = pagename
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
69 self.previous = previous
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
70 self.current = current
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
71
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
72
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
73 class SubscribedToPageEvent(PageEvent):
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
74 def __init__(self, request, pagename, username):
2094
9ee68c8b409b Style fixes as suggested by Thomas.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
75 PageEvent.__init__(self, request)
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
76 self.pagename = pagename
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
77 self.username = username
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
78
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
79
2091
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
80 class JabberIDSetEvent(Event):
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
81 """ Sent when user changes her Jabber ID """
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
82 def __init__(self, request, jid):
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
83 Event.__init__(self, request)
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
84 self.jid = jid
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
85
2095
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
86 class JabberIDUnsetEvent(Event):
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
87 """ Sent when Jabber ID is no longer used
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
88
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
89 Obviously this will be usually sent along with JabberIDSetEvent,
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
90 because we require user's jabber id to be unique by default.
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
91 """
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
92 def __init__(self, request, jid):
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
93 Event.__init__(self, request)
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
94 self.jid = jid
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
95
2145
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
96 class UserCreatedEvent(Event):
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
97 """ Sent when a new user has been created """
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
98
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
99 def __init__(self, request, user):
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
100 Event.__init__(self, request)
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
101 self.user = user
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
102
2095
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
103 def _register_handlers(cfg):
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
104 """Create a list of available event handlers.
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
105
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
106 Each handler is a handle() function defined in an plugin,
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
107 pretty much like in case of actions.
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
108
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
109 TODO: maybe make it less dumb? ;-)"""
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
110
2095
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
111 global _event_handlers
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
112
2095
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
113 _event_handlers = []
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
114 names = wikiutil.getPlugins("events", cfg)
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
115
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
116 for name in names:
2073
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
117 try:
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
118 handler = wikiutil.importPlugin(cfg, "events", name, "handle")
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
119 except PluginAttributeError:
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
120 handler = None
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
121
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
122 if handler is not None:
2095
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
123 _event_handlers.append(handler)
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
124
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
125
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
126 def send_event(event):
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
127 """Function called from outside to process an event"""
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
128
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
129 # A list of messages generated by event handlers, passed back to caller
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
130 msg = []
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
131
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
132 # Find all available event handlers
2095
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
133 if _event_handlers is None:
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
134 _register_handlers(event.request.cfg)
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
135
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
136 # Try to handle the event with each available handler (for now)
2095
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
137 for handle in _event_handlers:
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
138 retval = handle(event)
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
139 if isinstance(retval, unicode):
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
140 msg.append(retval)
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
141
2076
0128bbaf0172 Add newlines at the end of files, fix some overzealous deletion.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2073
diff changeset
142 return msg