mercurial/ui.py
branchstable
changeset 24848 2f88821856eb
parent 24687 28d76bc069db
child 24883 09049042ab99
equal deleted inserted replaced
24847:b705e5ab3b07 24848:2f88821856eb
    74 
    74 
    75 class ui(object):
    75 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
    83         self._ocfg = config.config() # overlay
    84         self._ocfg = config.config() # overlay
    84         self._tcfg = config.config() # trusted
    85         self._tcfg = config.config() # trusted
   538 
   539 
   539     @util.propertycache
   540     @util.propertycache
   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
   552 
   556 
   553         If labeled is True, any labels associated with buffered
   557         If labeled is True, any labels associated with buffered
   583             for a in args:
   587             for a in args:
   584                 self.fout.write(str(a))
   588                 self.fout.write(str(a))
   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()
   592             for a in args:
   596             for a in args:
   593                 self.ferr.write(str(a))
   597                 self.ferr.write(str(a))
   832 
   836 
   833     def system(self, cmd, environ={}, cwd=None, onerr=None, errprefix=None):
   837     def system(self, cmd, environ={}, cwd=None, onerr=None, errprefix=None):
   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.
   842         only to call in exception handler. returns true if traceback
   849         only to call in exception handler. returns true if traceback
   843         printed.'''
   850         printed.'''