summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2012-10-16 17:09:40 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2012-10-16 17:09:40 +0900
commit9e94fbcd20ee59bbf280eb8687d502956b26fe4c (patch)
tree8d1c495ae39a511a3ec41d919c104c017a699652
parentfa27eb4280e2218caf50b9e613fa46335cdc2a13 (diff)
downloadpygerrit-9e94fbcd20ee59bbf280eb8687d502956b26fe4c.tar.gz
Move SSH client from stream class to main client class
So it can be reused in query functionality that will be added later. Change-Id: I361aaf8fe8aa9107a94757606a3a1837b6a448ab
-rw-r--r--pygerrit/client.py5
-rw-r--r--pygerrit/stream.py9
2 files changed, 7 insertions, 7 deletions
diff --git a/pygerrit/client.py b/pygerrit/client.py
index 1d5fa44..b501b92 100644
--- a/pygerrit/client.py
+++ b/pygerrit/client.py
@@ -28,6 +28,7 @@ from Queue import Queue, Empty, Full
from pygerrit.error import GerritError
from pygerrit.events import GerritEventFactory
+from pygerrit.ssh import GerritSSHClient
from pygerrit.stream import GerritStream
@@ -37,14 +38,14 @@ class GerritClient(object):
def __init__(self, host):
self._factory = GerritEventFactory()
- self._host = host
self._events = Queue()
self._stream = None
+ self._ssh_client = GerritSSHClient(host)
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 = GerritStream(self, ssh_client=self._ssh_client)
self._stream.start()
def stop_event_stream(self):
diff --git a/pygerrit/stream.py b/pygerrit/stream.py
index d324422..f9ad55e 100644
--- a/pygerrit/stream.py
+++ b/pygerrit/stream.py
@@ -30,7 +30,6 @@ import json
from select import poll, POLLIN
from threading import Thread, Event
-from pygerrit.ssh import GerritSSHClient
from pygerrit.error import GerritError
from pygerrit.events import GerritEvent, GerritEventFactory
@@ -49,11 +48,11 @@ class GerritStream(Thread):
""" Gerrit events stream handler. """
- def __init__(self, gerrit, host):
+ def __init__(self, gerrit, ssh_client):
Thread.__init__(self)
self.daemon = True
self._gerrit = gerrit
- self._host = host
+ self._ssh_client = ssh_client
self._stop = Event()
def stop(self):
@@ -63,8 +62,8 @@ class GerritStream(Thread):
def run(self):
""" Listen to the stream and send events to the client. """
try:
- client = GerritSSHClient(self._host)
- _stdin, stdout, _stderr = client.run_gerrit_command("stream-events")
+ _stdin, stdout, _stderr = \
+ self._ssh_client.run_gerrit_command("stream-events")
p = poll()
p.register(stdout.channel)
while not self._stop.is_set():