1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

minor improvements to display

This commit is contained in:
Brian Coca 2015-07-25 09:14:41 -04:00
parent 0dc1cbd6b9
commit b19eb0f4dc

View file

@ -47,6 +47,7 @@ if C.DEFAULT_LOG_PATH:
else: else:
logger = None logger = None
debug_lock = Lock()
class Display: class Display:
@ -62,7 +63,6 @@ class Display:
self.cowsay = None self.cowsay = None
self.noncow = os.getenv("ANSIBLE_COW_SELECTION",None) self.noncow = os.getenv("ANSIBLE_COW_SELECTION",None)
self.set_cowsay_info() self.set_cowsay_info()
#self.debug_lock = Lock()
def set_cowsay_info(self): def set_cowsay_info(self):
@ -90,7 +90,7 @@ class Display:
# FIXME: this needs to be implemented # FIXME: this needs to be implemented
#msg = utils.sanitize_output(msg) #msg = utils.sanitize_output(msg)
msg2 = msg msg2 = self._safe_output(msg, stderr=stderr)
if color: if color:
msg2 = stringc(msg, color) msg2 = stringc(msg, color)
@ -98,8 +98,10 @@ class Display:
b_msg2 = to_bytes(msg2) b_msg2 = to_bytes(msg2)
if not stderr: if not stderr:
print(b_msg2) print(b_msg2)
sys.stdout.flush()
else: else:
print(b_msg2, file=sys.stderr) print(b_msg2, file=sys.stderr)
sys.stderr.flush()
if logger and not screen_only: if logger and not screen_only:
while msg.startswith("\n"): while msg.startswith("\n"):
@ -127,11 +129,9 @@ class Display:
def debug(self, msg): def debug(self, msg):
if C.DEFAULT_DEBUG: if C.DEFAULT_DEBUG:
# FIXME: enable when display is inherited to all debug_lock.acquire()
#self.debug_lock.acquire()
self.display("%6d %0.5f: %s" % (os.getpid(), time.time(), msg), color='dark gray') self.display("%6d %0.5f: %s" % (os.getpid(), time.time(), msg), color='dark gray')
sys.stdout.flush() debug_lock.release()
#self.debug_lock.release()
def verbose(self, msg, host=None, caplevel=2): def verbose(self, msg, host=None, caplevel=2):
# FIXME: this needs to be implemented # FIXME: this needs to be implemented
@ -223,9 +223,15 @@ class Display:
def prompt(self, msg): 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) msg = to_bytes(msg, sys.stdout.encoding)
elif stderr and sys.stderr.encoding:
msg = to_bytes(msg, sys.stderr.encoding)
else: else:
msg = to_bytes(msg) msg = to_bytes(msg)
return raw_input(msg) return msg