summaryrefslogtreecommitdiff
path: root/pygerrit/client.py
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2012-08-24 13:58:33 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2012-09-11 13:28:51 +0900
commitd8db31b4e99afef93534c84254e49036b348b905 (patch)
tree53ec5323abcdc025d26a93ded3112981194e1820 /pygerrit/client.py
parentce372a4808dfaad89cad6f74d7c618ae2c5a2111 (diff)
downloadpygerrit-d8db31b4e99afef93534c84254e49036b348b905.tar.gz
Refactor event stream handling to use SSH client
Change-Id: I4953be92719fddeb7c23c2559ffe954c452cc131
Diffstat (limited to 'pygerrit/client.py')
-rw-r--r--pygerrit/client.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/pygerrit/client.py b/pygerrit/client.py
index f72d70f..e570ece 100644
--- a/pygerrit/client.py
+++ b/pygerrit/client.py
@@ -4,6 +4,7 @@ from Queue import Queue, Empty, Full
from pygerrit.error import GerritError
from pygerrit.events import GerritEventFactory
+from pygerrit.stream import GerritStream
class GerritClient(object):
@@ -14,13 +15,28 @@ class GerritClient(object):
self._factory = GerritEventFactory()
self._host = host
self._events = Queue()
+ self._stream = None
+
+ def start_event_stream(self):
+ """ Start streaming events from `gerrit stream-events`. """
+ if not self._stream:
+ self._stream = GerritStream(self, host=self._host)
+ self._stream.start()
+
+ def stop_event_stream(self):
+ """ Stop streaming events from `gerrit stream-events`."""
+ if self._stream:
+ self._stream.stop()
+ self._stream = None
+ with self._events.mutex:
+ self._events.queue.clear()
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
+ - `block` is False and there is no event available in the queue, or
+ - `block` is True and no event is available within the time
specified by `timeout`.
"""