mirror of
https://github.com/facebook/sapling.git
synced 2024-10-08 15:57:43 +03:00
ui: pushbuffer can now also capture stderr
We need an easy way to capture both stderr and stdout during bundle2 processing of a remote bundle. This changeset adds simple changes to the `ui` class to make this possible. I expect the interface to change in future releases as bundle2 will probably want to distinguish stdout and stderr. The current change will, however, do for now.
This commit is contained in:
parent
53ffee95a2
commit
2feab6f005
@ -12,7 +12,10 @@ from node import hex
|
|||||||
|
|
||||||
class ui(object):
|
class ui(object):
|
||||||
def __init__(self, src=None):
|
def __init__(self, src=None):
|
||||||
|
# _buffers: used for temporary capture of output
|
||||||
self._buffers = []
|
self._buffers = []
|
||||||
|
# _bufferstates: Should the temporary capture includes stderr
|
||||||
|
self._bufferstates = []
|
||||||
self.quiet = self.verbose = self.debugflag = self.tracebackflag = False
|
self.quiet = self.verbose = self.debugflag = self.tracebackflag = False
|
||||||
self._reportuntrusted = True
|
self._reportuntrusted = True
|
||||||
self._ocfg = config.config() # overlay
|
self._ocfg = config.config() # overlay
|
||||||
@ -471,8 +474,12 @@ class ui(object):
|
|||||||
path = self.config('paths', default)
|
path = self.config('paths', default)
|
||||||
return path or loc
|
return path or loc
|
||||||
|
|
||||||
def pushbuffer(self):
|
def pushbuffer(self, error=False):
|
||||||
|
"""install a buffer to capture standar output of the ui object
|
||||||
|
|
||||||
|
If error is True, the error output will be captured too."""
|
||||||
self._buffers.append([])
|
self._buffers.append([])
|
||||||
|
self._bufferstates.append(error)
|
||||||
|
|
||||||
def popbuffer(self, labeled=False):
|
def popbuffer(self, labeled=False):
|
||||||
'''pop the last buffer and return the buffered output
|
'''pop the last buffer and return the buffered output
|
||||||
@ -484,6 +491,7 @@ class ui(object):
|
|||||||
is being buffered so it can be captured and parsed or
|
is being buffered so it can be captured and parsed or
|
||||||
processed, labeled should not be set to True.
|
processed, labeled should not be set to True.
|
||||||
'''
|
'''
|
||||||
|
self._bufferstates.pop()
|
||||||
return "".join(self._buffers.pop())
|
return "".join(self._buffers.pop())
|
||||||
|
|
||||||
def write(self, *args, **opts):
|
def write(self, *args, **opts):
|
||||||
@ -511,6 +519,8 @@ class ui(object):
|
|||||||
|
|
||||||
def write_err(self, *args, **opts):
|
def write_err(self, *args, **opts):
|
||||||
try:
|
try:
|
||||||
|
if self._bufferstates and self._bufferstates[-1]:
|
||||||
|
return self.write(*args, **opts)
|
||||||
if not getattr(self.fout, 'closed', False):
|
if not getattr(self.fout, 'closed', False):
|
||||||
self.fout.flush()
|
self.fout.flush()
|
||||||
for a in args:
|
for a in args:
|
||||||
|
Loading…
Reference in New Issue
Block a user