diff options
Diffstat (limited to 'pygerrit/stream.py')
| -rw-r--r-- | pygerrit/stream.py | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/pygerrit/stream.py b/pygerrit/stream.py index a9f94ae..dcf57ba 100644 --- a/pygerrit/stream.py +++ b/pygerrit/stream.py @@ -26,23 +26,12 @@ Class to listen to the Gerrit event stream and dispatch events. """ -import json import logging from select import select from threading import Thread, Event from .error import GerritError -from .events import GerritEvent, GerritEventFactory - - -@GerritEventFactory.register("gerrit-stream-error") -class GerritStreamErrorEvent(GerritEvent): - - """ Represents an error when handling the gerrit event stream. """ - - def __init__(self, json_data): - super(GerritStreamErrorEvent, self).__init__() - self.error = json_data["error"] +from .events import ErrorEvent class GerritStream(Thread): @@ -62,16 +51,14 @@ class GerritStream(Thread): def _error_event(self, error): """ Dispatch `error` to the Gerrit client. """ - json_data = json.loads('{"type":"gerrit-stream-error",' - '"error":"%s"}' % str(error)) - self._gerrit.put_event(json_data) + self._gerrit.put_event(ErrorEvent.error_json(str(error))) def run(self): """ Listen to the stream and send events to the client. """ try: result = self._ssh_client.run_gerrit_command("stream-events") - except GerritError as e: - self._error_event(e) + except GerritError as err: + self._error_event(err) else: stdout = result.stdout inputready, _outputready, _exceptready = \ @@ -79,10 +66,8 @@ class GerritStream(Thread): while not self._stop.is_set(): for _event in inputready: try: - line = stdout.readline() - json_data = json.loads(line) - self._gerrit.put_event(json_data) - except (ValueError, IOError) as err: + self._gerrit.put_event(stdout.readline()) + except IOError as err: self._error_event(err) except GerritError as err: logging.error("Failed to put event: %s", err) |
