comparison mercurial/commandserver.py @ 22990:a0e81aa94125

cmdserver: make server streams switchable In 'unix' mode, server instance will be created per connection, and fin/fout are set to socket files.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 27 Sep 2014 15:10:14 +0900
parents dc8803ce3dfe
children 840be5ca03e1
comparison
equal deleted inserted replaced
22989:dc8803ce3dfe 22990:a0e81aa94125
124 raise AttributeError(attr) 124 raise AttributeError(attr)
125 return getattr(self.in_, attr) 125 return getattr(self.in_, attr)
126 126
127 class server(object): 127 class server(object):
128 """ 128 """
129 Listens for commands on stdin, runs them and writes the output on a channel 129 Listens for commands on fin, runs them and writes the output on a channel
130 based stream to stdout. 130 based stream to fout.
131 """ 131 """
132 def __init__(self, ui, repo): 132 def __init__(self, ui, repo, fin, fout):
133 self.cwd = os.getcwd() 133 self.cwd = os.getcwd()
134 134
135 logpath = ui.config("cmdserver", "log", None) 135 logpath = ui.config("cmdserver", "log", None)
136 if logpath: 136 if logpath:
137 global logfile 137 global logfile
138 if logpath == '-': 138 if logpath == '-':
139 # write log on a special 'd' (debug) channel 139 # write log on a special 'd' (debug) channel
140 logfile = channeledoutput(sys.stdout, 'd') 140 logfile = channeledoutput(fout, 'd')
141 else: 141 else:
142 logfile = open(logpath, 'a') 142 logfile = open(logpath, 'a')
143 143
144 if repo: 144 if repo:
145 # the ui here is really the repo ui so take its baseui so we don't 145 # the ui here is really the repo ui so take its baseui so we don't
149 self.repoui = repo.ui 149 self.repoui = repo.ui
150 else: 150 else:
151 self.ui = ui 151 self.ui = ui
152 self.repo = self.repoui = None 152 self.repo = self.repoui = None
153 153
154 self.cerr = channeledoutput(sys.stdout, 'e') 154 self.cerr = channeledoutput(fout, 'e')
155 self.cout = channeledoutput(sys.stdout, 'o') 155 self.cout = channeledoutput(fout, 'o')
156 self.cin = channeledinput(sys.stdin, sys.stdout, 'I') 156 self.cin = channeledinput(fin, fout, 'I')
157 self.cresult = channeledoutput(sys.stdout, 'r') 157 self.cresult = channeledoutput(fout, 'r')
158 158
159 self.client = sys.stdin 159 self.client = fin
160 160
161 def _read(self, size): 161 def _read(self, size):
162 if not size: 162 if not size:
163 return '' 163 return ''
164 164
246 246
247 return 0 247 return 0
248 248
249 class pipeservice(object): 249 class pipeservice(object):
250 def __init__(self, ui, repo, opts): 250 def __init__(self, ui, repo, opts):
251 self.server = server(ui, repo) 251 self.server = server(ui, repo, sys.stdin, sys.stdout)
252 252
253 def init(self): 253 def init(self):
254 pass 254 pass
255 255
256 def run(self): 256 def run(self):