##// END OF EJS Templates
ui: allow capture of subprocess output...
Pierre-Yves David -
r24848:2f888218 stable
parent child Browse files
Show More
@@ -445,7 +445,7 b' class colorui(uimod.ui):'
445 return super(colorui, self).write_err(*args, **opts)
445 return super(colorui, self).write_err(*args, **opts)
446
446
447 label = opts.get('label', '')
447 label = opts.get('label', '')
448 if self._bufferstates and self._bufferstates[-1]:
448 if self._bufferstates and self._bufferstates[-1][0]:
449 return self.write(*args, **opts)
449 return self.write(*args, **opts)
450 if self._colormode == 'win32':
450 if self._colormode == 'win32':
451 for a in args:
451 for a in args:
@@ -76,7 +76,8 b' class ui(object):'
76 def __init__(self, src=None):
76 def __init__(self, src=None):
77 # _buffers: used for temporary capture of output
77 # _buffers: used for temporary capture of output
78 self._buffers = []
78 self._buffers = []
79 # _bufferstates: Should the temporary capture includes stderr
79 # _bufferstates:
80 # should the temporary capture include stderr and subprocess output
80 self._bufferstates = []
81 self._bufferstates = []
81 self.quiet = self.verbose = self.debugflag = self.tracebackflag = False
82 self.quiet = self.verbose = self.debugflag = self.tracebackflag = False
82 self._reportuntrusted = True
83 self._reportuntrusted = True
@@ -540,12 +541,15 b' class ui(object):'
540 def paths(self):
541 def paths(self):
541 return paths(self)
542 return paths(self)
542
543
543 def pushbuffer(self, error=False):
544 def pushbuffer(self, error=False, subproc=False):
544 """install a buffer to capture standard output of the ui object
545 """install a buffer to capture standard output of the ui object
545
546
546 If error is True, the error output will be captured too."""
547 If error is True, the error output will be captured too.
548
549 If subproc is True, output from subprocesses (typically hooks) will be
550 captured too."""
547 self._buffers.append([])
551 self._buffers.append([])
548 self._bufferstates.append(error)
552 self._bufferstates.append((error, subproc))
549
553
550 def popbuffer(self, labeled=False):
554 def popbuffer(self, labeled=False):
551 '''pop the last buffer and return the buffered output
555 '''pop the last buffer and return the buffered output
@@ -585,7 +589,7 b' class ui(object):'
585
589
586 def write_err(self, *args, **opts):
590 def write_err(self, *args, **opts):
587 try:
591 try:
588 if self._bufferstates and self._bufferstates[-1]:
592 if self._bufferstates and self._bufferstates[-1][0]:
589 return self.write(*args, **opts)
593 return self.write(*args, **opts)
590 if not getattr(self.fout, 'closed', False):
594 if not getattr(self.fout, 'closed', False):
591 self.fout.flush()
595 self.fout.flush()
@@ -834,8 +838,11 b' class ui(object):'
834 '''execute shell command with appropriate output stream. command
838 '''execute shell command with appropriate output stream. command
835 output will be redirected if fout is not stdout.
839 output will be redirected if fout is not stdout.
836 '''
840 '''
841 out = self.fout
842 if util.any(s[1] for s in self._bufferstates):
843 out = self
837 return util.system(cmd, environ=environ, cwd=cwd, onerr=onerr,
844 return util.system(cmd, environ=environ, cwd=cwd, onerr=onerr,
838 errprefix=errprefix, out=self.fout)
845 errprefix=errprefix, out=out)
839
846
840 def traceback(self, exc=None, force=False):
847 def traceback(self, exc=None, force=False):
841 '''print exception traceback if traceback printing enabled or forced.
848 '''print exception traceback if traceback printing enabled or forced.
General Comments 0
You need to be logged in to leave comments. Login now