285 |
285 |
286 class channeledsystem(object): |
286 class channeledsystem(object): |
287 """Propagate ui.system() request in the following format: |
287 """Propagate ui.system() request in the following format: |
288 |
288 |
289 payload length (unsigned int), |
289 payload length (unsigned int), |
|
290 type, '\0', |
290 cmd, '\0', |
291 cmd, '\0', |
291 cwd, '\0', |
292 cwd, '\0', |
292 envkey, '=', val, '\0', |
293 envkey, '=', val, '\0', |
293 ... |
294 ... |
294 envkey, '=', val |
295 envkey, '=', val |
295 |
296 |
296 and waits: |
297 if type == 'system', waits for: |
297 |
298 |
298 exitcode length (unsigned int), |
299 exitcode length (unsigned int), |
299 exitcode (int) |
300 exitcode (int) |
300 """ |
301 """ |
301 def __init__(self, in_, out, channel): |
302 def __init__(self, in_, out, channel): |
302 self.in_ = in_ |
303 self.in_ = in_ |
303 self.out = out |
304 self.out = out |
304 self.channel = channel |
305 self.channel = channel |
305 |
306 |
306 def __call__(self, cmd, environ, cwd): |
307 def __call__(self, cmd, environ, cwd, type='system'): |
307 args = [util.quotecommand(cmd), os.path.abspath(cwd or '.')] |
308 args = [type, util.quotecommand(cmd), os.path.abspath(cwd or '.')] |
308 args.extend('%s=%s' % (k, v) for k, v in environ.iteritems()) |
309 args.extend('%s=%s' % (k, v) for k, v in environ.iteritems()) |
309 data = '\0'.join(args) |
310 data = '\0'.join(args) |
310 self.out.write(struct.pack('>cI', self.channel, len(data))) |
311 self.out.write(struct.pack('>cI', self.channel, len(data))) |
311 self.out.write(data) |
312 self.out.write(data) |
312 self.out.flush() |
313 self.out.flush() |