comparison hglib/client.py @ 90:b894c2222dff

client: replace usage of namedtuple for python 2.4 compatibility
author Idan Kamara <idankk86@gmail.com>
date Thu, 22 Dec 2011 19:12:39 +0200
parents 351d2799f145
children 0383fc37102b
comparison
equal deleted inserted replaced
89:351d2799f145 90:b894c2222dff
1 import subprocess, os, struct, cStringIO, collections, re 1 import subprocess, os, struct, cStringIO, re
2 import hglib, error, util, templates, merge 2 import hglib, error, util, templates, merge
3 3
4 from util import cmdbuilder 4 from util import cmdbuilder
5
6 class revision(tuple):
7 def __new__(cls, rev, node, tags, branch, author, desc):
8 return tuple.__new__(cls, (rev, node, tags, branch, author, desc))
9
10 @property
11 def rev(self):
12 return self[0]
13
14 @property
15 def node(self):
16 return self[1]
17
18 @property
19 def tags(self):
20 return self[2]
21
22 @property
23 def branch(self):
24 return self[3]
25
26 @property
27 def author(self):
28 return self[4]
29
30 @property
31 def desc(self):
32 return self[5]
5 33
6 class hgclient(object): 34 class hgclient(object):
7 inputfmt = '>I' 35 inputfmt = '>I'
8 outputfmt = '>cI' 36 outputfmt = '>cI'
9 outputfmtsize = struct.calcsize(outputfmt) 37 outputfmtsize = struct.calcsize(outputfmt)
10 retfmt = '>i' 38 retfmt = '>i'
11
12 revision = collections.namedtuple('revision', 'rev, node, tags, '
13 'branch, author, desc')
14 39
15 def __init__(self, path, encoding, configs): 40 def __init__(self, path, encoding, configs):
16 args = [hglib.HGPATH, 'serve', '--cmdserver', 'pipe', 41 args = [hglib.HGPATH, 'serve', '--cmdserver', 'pipe',
17 '--config', 'ui.interactive=True'] 42 '--config', 'ui.interactive=True']
18 if path: 43 if path:
66 return channel, self.server.stdout.read(length) 91 return channel, self.server.stdout.read(length)
67 92
68 def _parserevs(self, splitted): 93 def _parserevs(self, splitted):
69 ''' splitted is a list of fields according to our rev.style, where each 6 94 ''' splitted is a list of fields according to our rev.style, where each 6
70 fields compose one revision. ''' 95 fields compose one revision. '''
71 return [self.revision._make(rev) for rev in util.grouper(6, splitted)] 96 return [revision(*rev) for rev in util.grouper(6, splitted)]
72 97
73 def runcommand(self, args, inchannels, outchannels): 98 def runcommand(self, args, inchannels, outchannels):
74 def writeblock(data): 99 def writeblock(data):
75 self.server.stdin.write(struct.pack(self.inputfmt, len(data))) 100 self.server.stdin.write(struct.pack(self.inputfmt, len(data)))
76 self.server.stdin.write(data) 101 self.server.stdin.write(data)