summaryrefslogtreecommitdiff
path: root/pygerrit/client.py
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2012-10-23 18:56:32 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2012-10-24 10:22:07 +0900
commitc8ad56f37edb69f46fdc1e3cecc14a760f34f0a1 (patch)
tree10c30670fd04dd54ff1381eb5c343a68f278c840 /pygerrit/client.py
parentd309677f9dd631b6a956659dd45ef91e4944656d (diff)
downloadpygerrit-c8ad56f37edb69f46fdc1e3cecc14a760f34f0a1.tar.gz
Refactor getting the Gerrit version
Move the functionality to get the Gerrit version from the main client into the SSH client and reimplement it. First attempt to get the version from the underlying Paramiko SSH client. If that fails, fall back to using the `gerrit version` command as before. Get and print the version in the example script. Change-Id: Ia79853f80f898b43c301fcecee61fdfdb75e9811
Diffstat (limited to 'pygerrit/client.py')
-rw-r--r--pygerrit/client.py19
1 files changed, 3 insertions, 16 deletions
diff --git a/pygerrit/client.py b/pygerrit/client.py
index a6bb77f..5ab3950 100644
--- a/pygerrit/client.py
+++ b/pygerrit/client.py
@@ -34,8 +34,6 @@ from pygerrit.models import Change
from pygerrit.ssh import GerritSSHClient
from pygerrit.stream import GerritStream
-_GERRIT_VERSION_PREFIX = "gerrit version "
-
class GerritClient(object):
@@ -46,21 +44,10 @@ class GerritClient(object):
self._events = Queue()
self._stream = None
self._ssh_client = GerritSSHClient(host)
- self._gerrit_version = self._get_gerrit_version()
-
- def _get_gerrit_version(self):
- """ Run `gerrit version` to get the version of Gerrit connected to.
- Return the version as a string. Empty if version was not returned.
-
- """
- _stdin, stdout, _stderr = self._ssh_client.run_gerrit_command("version")
- version_string = stdout.read()
- if version_string:
- if version_string.startswith(_GERRIT_VERSION_PREFIX):
- return version_string[len(_GERRIT_VERSION_PREFIX):].strip()
- return version_string.strip()
- return ""
+ def gerrit_version(self):
+ """ Get the version of Gerrit that is connected to. """
+ return self._ssh_client.get_remote_version()
def query(self, term):
""" Run `gerrit query` with the given term.