summaryrefslogtreecommitdiff
path: root/lib/ansible/utils
diff options
context:
space:
mode:
authorBrian Coca <brian.coca+git@gmail.com>2015-07-25 09:14:41 -0400
committerBrian Coca <brian.coca+git@gmail.com>2015-07-25 09:15:33 -0400
commitb19eb0f4dcd576fe758cda43bb5b73b2e3deda6a (patch)
tree03ff1b0075f9d75aca81019af5438255c55c790f /lib/ansible/utils
parent0dc1cbd6b95c26910bc3541cbb4037c768710d6c (diff)
downloadansible-b19eb0f4dcd576fe758cda43bb5b73b2e3deda6a.tar.gz
minor improvements to display
Diffstat (limited to 'lib/ansible/utils')
-rw-r--r--lib/ansible/utils/display.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py
index 850a77424f..42ebd1a90f 100644
--- a/lib/ansible/utils/display.py
+++ b/lib/ansible/utils/display.py
@@ -47,6 +47,7 @@ if C.DEFAULT_LOG_PATH:
else:
logger = None
+debug_lock = Lock()
class Display:
@@ -62,7 +63,6 @@ class Display:
self.cowsay = None
self.noncow = os.getenv("ANSIBLE_COW_SELECTION",None)
self.set_cowsay_info()
- #self.debug_lock = Lock()
def set_cowsay_info(self):
@@ -90,7 +90,7 @@ class Display:
# FIXME: this needs to be implemented
#msg = utils.sanitize_output(msg)
- msg2 = msg
+ msg2 = self._safe_output(msg, stderr=stderr)
if color:
msg2 = stringc(msg, color)
@@ -98,8 +98,10 @@ class Display:
b_msg2 = to_bytes(msg2)
if not stderr:
print(b_msg2)
+ sys.stdout.flush()
else:
print(b_msg2, file=sys.stderr)
+ sys.stderr.flush()
if logger and not screen_only:
while msg.startswith("\n"):
@@ -127,11 +129,9 @@ class Display:
def debug(self, msg):
if C.DEFAULT_DEBUG:
- # FIXME: enable when display is inherited to all
- #self.debug_lock.acquire()
+ debug_lock.acquire()
self.display("%6d %0.5f: %s" % (os.getpid(), time.time(), msg), color='dark gray')
- sys.stdout.flush()
- #self.debug_lock.release()
+ debug_lock.release()
def verbose(self, msg, host=None, caplevel=2):
# FIXME: this needs to be implemented
@@ -223,9 +223,15 @@ class Display:
def prompt(self, msg):
- if sys.stdout.encoding:
+ return raw_input(self._safe_output(msg))
+
+ def _safe_output(self, msg, stderr=False):
+
+ if not stderr and sys.stdout.encoding:
msg = to_bytes(msg, sys.stdout.encoding)
+ elif stderr and sys.stderr.encoding:
+ msg = to_bytes(msg, sys.stderr.encoding)
else:
msg = to_bytes(msg)
- return raw_input(msg)
+ return msg