##// END OF EJS Templates
convert: add support to common commandline to access stdin of the process
Daniel Atallah -
r13759:49b818fd default
parent child Browse files
Show More
@@ -254,7 +254,7 b' class commandline(object):'
254 def postrun(self):
254 def postrun(self):
255 pass
255 pass
256
256
257 def _cmdline(self, cmd, *args, **kwargs):
257 def _cmdline(self, cmd, closestdin, *args, **kwargs):
258 cmdline = [self.command, cmd] + list(args)
258 cmdline = [self.command, cmd] + list(args)
259 for k, v in kwargs.iteritems():
259 for k, v in kwargs.iteritems():
260 if len(k) == 1:
260 if len(k) == 1:
@@ -271,16 +271,23 b' class commandline(object):'
271 cmdline = [util.shellquote(arg) for arg in cmdline]
271 cmdline = [util.shellquote(arg) for arg in cmdline]
272 if not self.ui.debugflag:
272 if not self.ui.debugflag:
273 cmdline += ['2>', util.nulldev]
273 cmdline += ['2>', util.nulldev]
274 cmdline += ['<', util.nulldev]
274 if closestdin:
275 cmdline += ['<', util.nulldev]
275 cmdline = ' '.join(cmdline)
276 cmdline = ' '.join(cmdline)
276 return cmdline
277 return cmdline
277
278
278 def _run(self, cmd, *args, **kwargs):
279 def _run(self, cmd, *args, **kwargs):
279 cmdline = self._cmdline(cmd, *args, **kwargs)
280 return self._dorun(util.popen, cmd, True, *args, **kwargs)
281
282 def _run2(self, cmd, *args, **kwargs):
283 return self._dorun(util.popen2, cmd, False, *args, **kwargs)
284
285 def _dorun(self, openfunc, cmd, closestdin, *args, **kwargs):
286 cmdline = self._cmdline(cmd, closestdin, *args, **kwargs)
280 self.ui.debug('running: %s\n' % (cmdline,))
287 self.ui.debug('running: %s\n' % (cmdline,))
281 self.prerun()
288 self.prerun()
282 try:
289 try:
283 return util.popen(cmdline)
290 return openfunc(cmdline)
284 finally:
291 finally:
285 self.postrun()
292 self.postrun()
286
293
@@ -336,8 +343,9 b' class commandline(object):'
336 self._argmax = self._argmax / 2 - 1
343 self._argmax = self._argmax / 2 - 1
337 return self._argmax
344 return self._argmax
338
345
339 def limit_arglist(self, arglist, cmd, *args, **kwargs):
346 def limit_arglist(self, arglist, cmd, closestdin, *args, **kwargs):
340 limit = self.getargmax() - len(self._cmdline(cmd, *args, **kwargs))
347 cmdlen = len(self._cmdline(cmd, closestdin, *args, **kwargs))
348 limit = self.getargmax() - cmdlen
341 bytes = 0
349 bytes = 0
342 fl = []
350 fl = []
343 for fn in arglist:
351 for fn in arglist:
@@ -353,7 +361,7 b' class commandline(object):'
353 yield fl
361 yield fl
354
362
355 def xargs(self, arglist, cmd, *args, **kwargs):
363 def xargs(self, arglist, cmd, *args, **kwargs):
356 for l in self.limit_arglist(arglist, cmd, *args, **kwargs):
364 for l in self.limit_arglist(arglist, cmd, True, *args, **kwargs):
357 self.run0(cmd, *(list(args) + l), **kwargs)
365 self.run0(cmd, *(list(args) + l), **kwargs)
358
366
359 class mapfile(dict):
367 class mapfile(dict):
General Comments 0
You need to be logged in to leave comments. Login now