forked from errbotio/plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gerrit.py
49 lines (39 loc) · 1.69 KB
/
gerrit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# This is a skeleton for Err plugins, use this to get started quickly.
from errbot import BotPlugin, botcmd
from pygerrit.client import GerritClient
import logging
class Gerrit(BotPlugin):
"""An Err plugin skeleton"""
min_err_version = '1.6.0' # Optional, but recommended
max_err_version = '2.0.0' # Optional, but recommended
def activate(self):
"""Triggers on plugin activation
You should delete it if you're not using it to
override any default behaviour"""
self.client = GerritClient("gerritssh")
self.client.gerrit_version()
self.client.start_event_stream()
self.start_poller(2, self._poll_event)
super(Gerrit, self).activate()
def deactivate(self):
"""Triggers on plugin deactivation
You should delete it if you're not using it to
override any default behaviour"""
logging.warn('Calling Stop Poller')
self.stop_poller(self._poll_event)
logging.warn('Calling Stop event stream')
self.client.stop_event_stream()
logging.warn('Calling super deavtivate')
super(Gerrit, self).deactivate()
def _poll_event(self):
logging.warn('Starting to listen for event')
event = self.client.get_event(block=True, timeout=1)
if event:
self.send('#mugsie-test', 'Got an Event', message_type='groupchat')
logging.warn('Stopped listening for event')
# Passing split_args_with=None will cause arguments to be split on any kind
# of whitespace, just like Python's split() does
@botcmd(split_args_with=None)
def example(self, mess, args):
"""A command which simply returns 'Example'"""
return "Example"