Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commandserver.py @ 22989:dc8803ce3dfe
cmdserver: switch service objects by mode
server class will be changed to accept fin/fout pair instead of mode string
so that it can interact with socket files.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 27 Sep 2014 15:04:46 +0900 |
parents | 32b77aba2772 |
children | a0e81aa94125 |
comparison
equal
deleted
inserted
replaced
22988:32b77aba2772 | 22989:dc8803ce3dfe |
---|---|
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 stdin, runs them and writes the output on a channel |
130 based stream to stdout. | 130 based stream to stdout. |
131 """ | 131 """ |
132 def __init__(self, ui, repo, mode): | 132 def __init__(self, ui, repo): |
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 |
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 if mode == 'pipe': | 154 self.cerr = channeledoutput(sys.stdout, 'e') |
155 self.cerr = channeledoutput(sys.stdout, 'e') | 155 self.cout = channeledoutput(sys.stdout, 'o') |
156 self.cout = channeledoutput(sys.stdout, 'o') | 156 self.cin = channeledinput(sys.stdin, sys.stdout, 'I') |
157 self.cin = channeledinput(sys.stdin, sys.stdout, 'I') | 157 self.cresult = channeledoutput(sys.stdout, 'r') |
158 self.cresult = channeledoutput(sys.stdout, 'r') | 158 |
159 | 159 self.client = sys.stdin |
160 self.client = sys.stdin | |
161 else: | |
162 raise util.Abort(_('unknown mode %s') % mode) | |
163 | 160 |
164 def _read(self, size): | 161 def _read(self, size): |
165 if not size: | 162 if not size: |
166 return '' | 163 return '' |
167 | 164 |
249 | 246 |
250 return 0 | 247 return 0 |
251 | 248 |
252 class pipeservice(object): | 249 class pipeservice(object): |
253 def __init__(self, ui, repo, opts): | 250 def __init__(self, ui, repo, opts): |
254 self.server = server(ui, repo, opts['cmdserver']) | 251 self.server = server(ui, repo) |
255 | 252 |
256 def init(self): | 253 def init(self): |
257 pass | 254 pass |
258 | 255 |
259 def run(self): | 256 def run(self): |
260 return self.server.serve() | 257 return self.server.serve() |
258 | |
259 _servicemap = { | |
260 'pipe': pipeservice, | |
261 } | |
262 | |
263 def createservice(ui, repo, opts): | |
264 mode = opts['cmdserver'] | |
265 try: | |
266 return _servicemap[mode](ui, repo, opts) | |
267 except KeyError: | |
268 raise util.Abort(_('unknown mode %s') % mode) |