blob: f72d70f4c3dbd56920942024f9eac2be58e8e70b (
plain)
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
|
""" Gerrit client interface. """
from Queue import Queue, Empty, Full
from pygerrit.error import GerritError
from pygerrit.events import GerritEventFactory
class GerritClient(object):
""" Gerrit client interface. """
def __init__(self, host):
self._factory = GerritEventFactory()
self._host = host
self._events = Queue()
def get_event(self, block=True, timeout=None):
""" Get the next event from the queue.
Return a `GerritEvent` instance, or None if:
- `block` was False and there is no event available in the queue, or
- `block` was True and no event was available within the time
specified by `timeout`.
"""
try:
return self._events.get(block, timeout)
except Empty:
return None
def put_event(self, json_data):
""" Create event from `json_data` and add it to the queue.
Raise GerritError if the queue is full, or the factory could not
create the event.
"""
try:
event = self._factory.create(json_data)
self._events.put(event)
except Full:
raise GerritError("Unable to add event: queue is full")
|