diff options
author | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-10-17 09:47:33 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-10-17 13:29:12 +0900 |
commit | 74a48a175f78438d474d5609dd66c4f79e12a099 (patch) | |
tree | 635c88ea6726e3e4c43a07e6effa0981dffa23db /pygerrit/client.py | |
parent | 947d08f46a82b68aa5466eb3792902ae4dba36ed (diff) | |
download | pygerrit-74a48a175f78438d474d5609dd66c4f79e12a099.tar.gz |
Get Gerrit version during client initialisation
Later the client might have functionality that only works on
certain versions of Gerrit. Store the Gerrit version during
initialisation.
Change-Id: Idcd35baf00d6cd583f6f85b68c4b0a0c3653344b
Diffstat (limited to 'pygerrit/client.py')
-rw-r--r-- | pygerrit/client.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/pygerrit/client.py b/pygerrit/client.py index 5b1a24d..a6bb77f 100644 --- a/pygerrit/client.py +++ b/pygerrit/client.py @@ -34,6 +34,8 @@ from pygerrit.models import Change from pygerrit.ssh import GerritSSHClient from pygerrit.stream import GerritStream +_GERRIT_VERSION_PREFIX = "gerrit version " + class GerritClient(object): @@ -44,6 +46,21 @@ 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 query(self, term): """ Run `gerrit query` with the given term. |