Mercurial > python-hglib
comparison 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 |
comparison
equal
deleted
inserted
replaced
40:238efe4fd7db | 41:e185c3922c68 |
---|---|
24 | 24 |
25 self.server = subprocess.Popen(args, stdin=subprocess.PIPE, | 25 self.server = subprocess.Popen(args, stdin=subprocess.PIPE, |
26 stdout=subprocess.PIPE, env=env) | 26 stdout=subprocess.PIPE, env=env) |
27 | 27 |
28 self._readhello() | 28 self._readhello() |
29 self._version = None | |
29 | 30 |
30 def _readhello(self): | 31 def _readhello(self): |
31 """ read the hello message the server sends when started """ | 32 """ read the hello message the server sends when started """ |
32 ch, msg = self._readchannel() | 33 ch, msg = self._readchannel() |
33 assert ch == 'o' | 34 assert ch == 'o' |
643 # filter out 'merging ...' lines | 644 # filter out 'merging ...' lines |
644 out = util.skiplines(out, 'merging ') | 645 out = util.skiplines(out, 'merging ') |
645 | 646 |
646 counters = out.rstrip().split(', ') | 647 counters = out.rstrip().split(', ') |
647 return tuple(int(s.split(' ', 1)[0]) for s in counters) | 648 return tuple(int(s.split(' ', 1)[0]) for s in counters) |
649 | |
650 @property | |
651 def version(self): | |
652 if self._version is None: | |
653 v = self.rawcommand(cmdbuilder('version', q=True)) | |
654 v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?', | |
655 v).groups()) | |
656 | |
657 for i in range(3): | |
658 try: | |
659 v[i] = int(v[i]) | |
660 except TypeError: | |
661 v[i] = 0 | |
662 | |
663 self._version = tuple(v) | |
664 | |
665 return self._version |