Merge lp:~stefanor/ibid/ibid-plugin-333213 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Merged
Approved by: Michael Gorven
Approved revision: 558
Merged at revision: 554
Proposed branch: lp:~stefanor/ibid/ibid-plugin-333213
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: None lines
To merge this branch: bzr merge lp:~stefanor/ibid/ibid-plugin-333213
Reviewer Review Type Date Requested Status
Michael Gorven Approve
Jonathan Hitchcock Approve
Review via email: mp+4047@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote :

Some mistakes in early commits fixed later, bleh.

Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve
Revision history for this message
Michael Gorven (mgorven) wrote :

 review approve
 status approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/core.py'
2--- ibid/core.py 2009-02-13 21:35:13 +0000
3+++ ibid/core.py 2009-03-01 14:29:51 +0000
4@@ -18,7 +18,7 @@
5 def _process(self, event):
6 for processor in ibid.processors:
7 try:
8- event = processor.process(event) or event
9+ processor.process(event)
10 except Exception:
11 self.log.exception(u"Exception occured in %s processor of %s plugin", processor.__class__.__name__, processor.name)
12
13
14=== modified file 'ibid/plugins/admin.py'
15--- ibid/plugins/admin.py 2009-02-13 21:19:45 +0000
16+++ ibid/plugins/admin.py 2009-03-01 14:29:51 +0000
17@@ -18,7 +18,6 @@
18 plugins.append(processor.name)
19
20 event.addresponse(', '.join(plugins))
21- return event
22
23 help['core'] = 'Reloads core modules.'
24 class ReloadCoreModules(Processor):
25
26=== modified file 'ibid/plugins/basic.py'
27--- ibid/plugins/basic.py 2009-02-13 21:19:45 +0000
28+++ ibid/plugins/basic.py 2009-03-01 14:29:51 +0000
29@@ -21,7 +21,6 @@
30 reply['action'] = True
31
32 event.addresponse(reply)
33- return event
34
35 help['redirect'] = u'Redirects the response to a command to a different channel.'
36 class RedirectCommand(Processor):
37
38=== modified file 'ibid/plugins/bzr.py'
39--- ibid/plugins/bzr.py 2009-02-18 10:41:14 +0000
40+++ ibid/plugins/bzr.py 2009-03-01 14:36:38 +0000
41@@ -111,7 +111,9 @@
42
43 @handler
44 def launchpad(self, event):
45- if ibid.sources[event.source.lower()].type != 'smtp' or 'X-Launchpad-Branch' not in event.headers:
46+ if event.source.lower() not in ibid.sources \
47+ or ibid.sources[event.source.lower()].type != 'smtp' \
48+ or 'X-Launchpad-Branch' not in event.headers:
49 return
50
51 event.processed = True
52
53=== modified file 'ibid/plugins/config.py'
54--- ibid/plugins/config.py 2009-02-13 21:55:56 +0000
55+++ ibid/plugins/config.py 2009-03-01 15:12:17 +0000
56@@ -47,7 +47,7 @@
57 for part in key.split('.'):
58 if part not in config:
59 event.addresponse(u'No such option')
60- return event
61+ return
62 config = config[part]
63 event.addresponse(unicode(config))
64
65
66=== modified file 'ibid/plugins/core.py'
67--- ibid/plugins/core.py 2009-02-23 20:29:44 +0000
68+++ ibid/plugins/core.py 2009-03-01 15:01:42 +0000
69@@ -34,7 +34,6 @@
70
71 event.addressed = matches.group(1)
72 event.message = new_message
73- return event
74
75 class Strip(Processor):
76
77@@ -59,8 +58,6 @@
78 if event.sender['nick'] == who:
79 event.processed = True
80
81- return event
82-
83 class Responses(Processor):
84
85 priority = 1600
86@@ -78,13 +75,12 @@
87 response['target'] = event.channel
88 if 'source' not in response:
89 response['source'] = event.source
90- if 'action' in response and ibid.sources[response['source'].lower()].type not in ('irc', 'silc'):
91+ if 'action' in response and (response['source'].lower() not in ibid.sources \
92+ or ibid.sources[response['source'].lower()].type not in ('irc', 'silc')):
93 response['reply'] = '* %s %s' % (ibid.config['botname'], response['reply'])
94 converted.append(response)
95
96 event.responses = converted
97- return event
98-
99
100 class Address(Processor):
101
102@@ -125,7 +121,6 @@
103 event.addresponse(choice(self.notauthed))
104 else:
105 event.addresponse(choice(self.complaints))
106- return event
107
108 class RateLimit(Processor):
109
110
111=== modified file 'ibid/plugins/dbus.py'
112--- ibid/plugins/dbus.py 2009-02-18 21:24:45 +0000
113+++ ibid/plugins/dbus.py 2009-03-01 14:29:51 +0000
114@@ -55,6 +55,5 @@
115 if response:
116 event['responses'].append(response)
117 event['processed'] = True
118- return event
119
120 # vi: set et sta sw=4 ts=4:
121
122=== modified file 'ibid/plugins/http.py'
123--- ibid/plugins/http.py 2009-02-03 18:03:49 +0000
124+++ ibid/plugins/http.py 2009-03-01 14:29:51 +0000
125@@ -30,4 +30,3 @@
126 reply = u'%s "%s"' % (reply, match.groups()[0].strip())
127
128 event.addresponse(reply)
129- return event
130
131=== modified file 'ibid/plugins/log.py'
132--- ibid/plugins/log.py 2009-02-23 20:43:40 +0000
133+++ ibid/plugins/log.py 2009-03-01 14:36:38 +0000
134@@ -20,7 +20,7 @@
135
136 def get_logfile(self, source, channel, when):
137 when = localtime(when)
138- if ibid.sources[source.lower()].type == 'jabber':
139+ if source.lower() in ibid.sources and ibid.sources[source.lower()].type == 'jabber':
140 channel = channel.split('/')[0]
141 filename = self.log % { 'source': source,
142 'channel': channel,
143
144=== modified file 'ibid/plugins/lookup.py'
145--- ibid/plugins/lookup.py 2009-02-22 10:37:32 +0000
146+++ ibid/plugins/lookup.py 2009-03-01 14:29:51 +0000
147@@ -58,7 +58,8 @@
148 try:
149 f = urlopen(self.za_url)
150 except Exception, e:
151- return event.addresponse(self.errors['open'])
152+ event.addresponse(self.errors['open'])
153+ return
154
155 s = "".join(f)
156 f.close()
157@@ -68,8 +69,9 @@
158 balls = self.za_re.findall(s)
159
160 if len(balls) != 14:
161- return event.addresponse(self.errors['balls'] % \
162- (14, len(balls), ", ".join(balls)))
163+ event.addresponse(self.errors['balls'] % \
164+ (14, len(balls), ", ".join(balls)))
165+ return
166
167 r += " ".join(balls[:6])
168 r += " (Bonus: %s), Lotto Plus: " % (balls[6], )
169
170=== modified file 'ibid/plugins/misc.py'
171--- ibid/plugins/misc.py 2009-02-23 20:29:44 +0000
172+++ ibid/plugins/misc.py 2009-03-01 15:12:17 +0000
173@@ -22,13 +22,12 @@
174 # Hi ... race condition.
175 if self.pot:
176 event.addresponse(u"There's already a pot on")
177- return event
178+ return
179
180 self.pot = [event.sender['nick']]
181 sleep(self.time)
182 event.addresponse(u"Coffee's ready for %s!" % u', '.join(self.pot))
183 self.pot = None
184- return event
185
186 @match('^coffee\s+(?:please|pls)$')
187 def coffee_accept(self, event):
188@@ -42,8 +41,6 @@
189 self.pot.append(event.sender['nick'])
190 event.addresponse(True)
191
192- return event
193-
194 version = resource_exists(__name__, '../.version') and resource_string(__name__, '../.version') or None
195
196 help['version'] = u"Show the Ibid version currently running"
197
198=== modified file 'ibid/plugins/morse.py'
199--- ibid/plugins/morse.py 2009-01-24 12:39:04 +0000
200+++ ibid/plugins/morse.py 2009-03-01 14:29:51 +0000
201@@ -73,8 +73,5 @@
202
203 if message.replace('-', '').replace('.', '').isspace():
204 event.addresponse(morse2text(message))
205- return event
206-
207 else:
208 event.addresponse(text2morse(message))
209- return event
210
211=== modified file 'ibid/plugins/roshambo.py'
212--- ibid/plugins/roshambo.py 2009-01-24 12:39:04 +0000
213+++ ibid/plugins/roshambo.py 2009-03-01 14:29:51 +0000
214@@ -24,6 +24,5 @@
215 reply = 'I win! I chose %s' % choices[bchoice]
216
217 event.addresponse(reply)
218- return event
219
220 # vi: set et sta sw=4 ts=4:
221
222=== modified file 'ibid/plugins/seen.py'
223--- ibid/plugins/seen.py 2009-02-18 19:05:10 +0000
224+++ ibid/plugins/seen.py 2009-03-01 14:29:51 +0000
225@@ -125,6 +125,5 @@
226
227 event.addresponse(reply)
228 session.close()
229- return event
230
231 # vi: set et sta sw=4 ts=4:
232
233=== modified file 'ibid/plugins/test.py'
234--- ibid/plugins/test.py 2009-01-12 17:35:59 +0000
235+++ ibid/plugins/test.py 2009-03-01 14:29:51 +0000
236@@ -9,7 +9,6 @@
237 def handler(self, event, delay):
238 sleep(float(delay))
239 event.addresponse('Done')
240- return event
241
242 class Authorise(Processor):
243
244@@ -27,4 +26,11 @@
245 event.addresponse({'reply': 'Test message', 'source': 'email', 'target': unicode(address)})
246 event.addresponse(u"I've emailed %s" % address)
247
248+class Except(Processor):
249+
250+ @match(r'^raise\s+exception$')
251+ def handler(self, event):
252+ event.addresponse("I'll except in a moment")
253+ raise Exception("Ow, that hurt.")
254+
255 # vi: set et sta sw=4 ts=4:
256
257=== modified file 'scripts/ibid-plugin'
258--- scripts/ibid-plugin 2009-02-23 20:43:40 +0000
259+++ scripts/ibid-plugin 2009-03-01 14:37:55 +0000
260@@ -1,14 +1,19 @@
261 #!/usr/bin/env python
262
263+import logging
264+import os
265+import sqlalchemy
266 from sys import argv, exit
267-from traceback import print_exc
268-import logging
269-
270-if len(argv) != 2:
271- print 'Usage: %s plugin' % (argv[0], )
272+
273+try:
274+ import readline
275+except ImportError:
276+ pass
277+
278+if len(argv) < 2:
279+ print 'Usage: %s plugin[s]' % (argv[0], )
280 exit(1)
281
282-import os
283 import ibid
284 import ibid.plugins
285 from ibid.config import FileConfig
286@@ -28,37 +33,60 @@
287 ibid.reload_reloader()
288 ibid.reloader.reload_databases()
289 ibid.reloader.reload_dispatcher()
290-ibid.reloader.load_processor(argv[1])
291+
292+plugins = argv[1:]
293+if len(argv[1:]) == 1 and argv[1] == "--all":
294+ plugins = ibid.config.get("load")
295+for plugin in plugins:
296+ ibid.reloader.load_processor(plugin)
297
298 username = unicode(os.getenv('USER'))
299 if not username:
300- username = u'test_plugin'
301+ username = u'tester'
302 session = ibid.databases.ibid()
303-identity = session.query(Identity).filter_by(identity=username).first()
304+try:
305+ identity = session.query(Identity).filter_by(identity=username).first()
306+except sqlalchemy.exc.ArgumentError:
307+ identity = None
308 if not identity:
309- identity = Identity(u'test_plugin',username)
310+ identity = Identity(u'test_source',username)
311 session.add(identity)
312 session.flush()
313 identity = session.query(Identity).filter_by(identity=username).first()
314 identity_id = identity.id
315
316+try:
317+ encoding = os.getenv("LANG").split(".")[1]
318+except:
319+ encoding = "ascii"
320+
321+log = logging.getLogger('scripts.ibid-plugin')
322+
323 while True:
324+ event = Event(u'test_source', u'message')
325+ event.sender['id'] = event.sender['connection'] = event.sender['nick'] = username
326+ event.identity = identity_id
327+ event.account = None
328+ event.addressed = True
329+ event.public = False
330+ event.channel = u"testchan"
331+
332 try:
333- event = Event('test_plugin', 'message')
334- event.sender['id'] = event.sender['connection'] = event.sender['nick'] = username
335- event.identity = identity_id
336- event.account = None
337- event.addressed = True
338- event.public = False
339- event.message = unicode(raw_input('Query: '))
340- for processor in ibid.processors:
341+ event.message = unicode(raw_input('Query: '), encoding)
342+ except KeyboardInterrupt:
343+ break
344+
345+ for processor in ibid.processors:
346+ try:
347 processor.process(event)
348- for response in event.responses:
349- if isinstance(response, dict):
350- response = response['reply']
351- print 'Response: %s' % response
352- #print event
353- except Exception, e:
354- print_exc()
355+ except Exception:
356+ log.exception(u"Exception occured in %s processor of %s plugin", processor.__class__.__name__, processor.name)
357+
358+ for response in event.responses:
359+ if isinstance(response, dict):
360+ response = response['reply']
361+ print 'Response: %s' % response
362+
363+print "\nExiting"
364
365 # vi: set et sta sw=4 ts=4:

Subscribers

People subscribed via source and target branches