mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Allow RedirectStdStreams
to behave correctly using with
. Allow flushing streams.
This commit is contained in:
parent
c4e485a8bf
commit
f51f35c148
@ -74,6 +74,7 @@ class RedirectStdStreams(object):
|
||||
|
||||
def __enter__(self):
|
||||
self.redirect()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self.unredirect()
|
||||
@ -90,14 +91,33 @@ class RedirectStdStreams(object):
|
||||
def unredirect(self):
|
||||
if not self.__redirected:
|
||||
return
|
||||
|
||||
try:
|
||||
self.__stdout.flush()
|
||||
self.__stdout.close()
|
||||
except ValueError:
|
||||
# already closed?
|
||||
pass
|
||||
try:
|
||||
self.__stderr.flush()
|
||||
self.__stderr.close()
|
||||
except ValueError:
|
||||
# already closed?
|
||||
pass
|
||||
|
||||
sys.stdout = self.old_stdout
|
||||
sys.stderr = self.old_stderr
|
||||
|
||||
def flush(self):
|
||||
if self.__redirected:
|
||||
try:
|
||||
self.__stdout.flush()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
self.__stderr.flush()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
class TestsLoggingHandler(object):
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user