diff hglib/client.py @ 41:e185c3922c68

client: add version command
author Idan Kamara <idankk86@gmail.com>
date Mon, 15 Aug 2011 22:46:45 +0300
parents 238efe4fd7db
children b6b75c71ac58
line wrap: on
line diff
--- a/hglib/client.py	Mon Aug 15 22:46:45 2011 +0300
+++ b/hglib/client.py	Mon Aug 15 22:46:45 2011 +0300
@@ -26,6 +26,7 @@
                                        stdout=subprocess.PIPE, env=env)
 
         self._readhello()
+        self._version = None
 
     def _readhello(self):
         """ read the hello message the server sends when started """
@@ -645,3 +646,20 @@
 
         counters = out.rstrip().split(', ')
         return tuple(int(s.split(' ', 1)[0]) for s in counters)
+
+    @property
+    def version(self):
+        if self._version is None:
+            v = self.rawcommand(cmdbuilder('version', q=True))
+            v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?',
+                              v).groups())
+
+            for i in range(3):
+                try:
+                    v[i] = int(v[i])
+                except TypeError:
+                    v[i] = 0
+
+            self._version = tuple(v)
+
+        return self._version