mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 22:51:23 -07:00
Ensure that we're dealing with byte str when we print or log messages
This commit is contained in:
parent
6d50a261c5
commit
49a148056c
1 changed files with 7 additions and 10 deletions
|
@ -28,6 +28,7 @@ import sys
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.utils.color import stringc
|
from ansible.utils.color import stringc
|
||||||
|
from ansible.utils.unicode import to_bytes
|
||||||
|
|
||||||
class Display:
|
class Display:
|
||||||
|
|
||||||
|
@ -70,25 +71,21 @@ class Display:
|
||||||
if color:
|
if color:
|
||||||
msg2 = stringc(msg, color)
|
msg2 = stringc(msg, color)
|
||||||
if not log_only:
|
if not log_only:
|
||||||
|
b_msg2 = to_bytes(msg2)
|
||||||
if not stderr:
|
if not stderr:
|
||||||
try:
|
print(b_msg2)
|
||||||
print(msg2)
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
print(msg2.encode('utf-8'))
|
|
||||||
else:
|
else:
|
||||||
try:
|
print(b_msg2, file=sys.stderr)
|
||||||
print(msg2, file=sys.stderr)
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
print(msg2.encode('utf-8'), file=sys.stderr)
|
|
||||||
if C.DEFAULT_LOG_PATH != '':
|
if C.DEFAULT_LOG_PATH != '':
|
||||||
while msg.startswith("\n"):
|
while msg.startswith("\n"):
|
||||||
msg = msg.replace("\n","")
|
msg = msg.replace("\n","")
|
||||||
|
b_msg = to_bytes(msg)
|
||||||
# FIXME: logger stuff needs to be implemented
|
# FIXME: logger stuff needs to be implemented
|
||||||
#if not screen_only:
|
#if not screen_only:
|
||||||
# if color == 'red':
|
# if color == 'red':
|
||||||
# logger.error(msg)
|
# logger.error(b_msg)
|
||||||
# else:
|
# else:
|
||||||
# logger.info(msg)
|
# logger.info(b_msg)
|
||||||
|
|
||||||
def vv(self, msg, host=None):
|
def vv(self, msg, host=None):
|
||||||
return self.verbose(msg, host=host, caplevel=1)
|
return self.verbose(msg, host=host, caplevel=1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue