mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Move uses of to_bytes, to_text, to_native to use the module_utils version (#17423)
We couldn't copy to_unicode, to_bytes, to_str into module_utils because of licensing. So once created it we had two sets of functions that did the same things but had different implementations. To remedy that, this change removes the ansible.utils.unicode versions of those functions.
This commit is contained in:
@@ -24,12 +24,10 @@ import difflib
|
||||
import warnings
|
||||
from copy import deepcopy
|
||||
|
||||
from ansible.compat.six import string_types
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.vars import strip_internal_keys
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.utils.color import stringc
|
||||
from ansible.utils.unicode import to_unicode
|
||||
from ansible.vars import strip_internal_keys
|
||||
|
||||
try:
|
||||
from __main__ import display as global_display
|
||||
@@ -37,14 +35,15 @@ except ImportError:
|
||||
from ansible.utils.display import Display
|
||||
global_display = Display()
|
||||
|
||||
__all__ = ["CallbackBase"]
|
||||
|
||||
try:
|
||||
from __main__ import cli
|
||||
except ImportError:
|
||||
# using API w/o cli
|
||||
# using API w/o cli
|
||||
cli = False
|
||||
|
||||
__all__ = ["CallbackBase"]
|
||||
|
||||
|
||||
class CallbackBase:
|
||||
|
||||
'''
|
||||
@@ -146,8 +145,8 @@ class CallbackBase:
|
||||
after_header = "after: %s" % diff['after_header']
|
||||
else:
|
||||
after_header = 'after'
|
||||
differ = difflib.unified_diff(to_unicode(diff['before']).splitlines(True),
|
||||
to_unicode(diff['after']).splitlines(True),
|
||||
differ = difflib.unified_diff(to_text(diff['before']).splitlines(True),
|
||||
to_text(diff['after']).splitlines(True),
|
||||
fromfile=before_header,
|
||||
tofile=after_header,
|
||||
fromfiledate='',
|
||||
@@ -166,7 +165,7 @@ class CallbackBase:
|
||||
if has_diff:
|
||||
ret.append('\n')
|
||||
if 'prepared' in diff:
|
||||
ret.append(to_unicode(diff['prepared']))
|
||||
ret.append(to_text(diff['prepared']))
|
||||
except UnicodeDecodeError:
|
||||
ret.append(">> the files are different, but the diff library cannot compare unicode strings\n\n")
|
||||
return u''.join(ret)
|
||||
@@ -362,4 +361,3 @@ class CallbackBase:
|
||||
|
||||
def v2_runner_retry(self, result):
|
||||
pass
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ __metaclass__ = type
|
||||
import os
|
||||
import time
|
||||
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
from ansible.utils.unicode import to_bytes
|
||||
|
||||
try:
|
||||
from junit_xml import TestSuite, TestCase
|
||||
@@ -40,6 +40,7 @@ except ImportError:
|
||||
except ImportError:
|
||||
HAS_ORDERED_DICT = False
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
"""
|
||||
This callback writes playbook output to a JUnit formatted XML file.
|
||||
@@ -181,7 +182,7 @@ class CallbackModule(CallbackBase):
|
||||
output_file = os.path.join(self._output_dir, '%s-%s.xml' % (self._playbook_name, time.time()))
|
||||
|
||||
with open(output_file, 'wb') as xml:
|
||||
xml.write(to_bytes(report, errors='strict'))
|
||||
xml.write(to_bytes(report, errors='surrogate_or_strict'))
|
||||
|
||||
def v2_playbook_on_start(self, playbook):
|
||||
self._playbook_path = playbook._file_name
|
||||
|
||||
@@ -23,9 +23,10 @@ import os
|
||||
import time
|
||||
import json
|
||||
|
||||
from ansible.utils.unicode import to_bytes
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
||||
# NOTE: in Ansible 1.2 or later general logging is available without
|
||||
# this plugin, just set ANSIBLE_LOG_PATH as an environment variable
|
||||
# or log_path in the DEFAULTS section of your ansible configuration
|
||||
|
||||
@@ -25,9 +25,10 @@ import smtplib
|
||||
import json
|
||||
|
||||
from ansible.compat.six import string_types
|
||||
from ansible.utils.unicode import to_bytes
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
||||
def mail(subject='Ansible error mail', sender=None, to=None, cc=None, bcc=None, body=None, smtphost=None):
|
||||
|
||||
if sender is None:
|
||||
@@ -84,7 +85,7 @@ class CallbackModule(CallbackBase):
|
||||
if ignore_errors:
|
||||
return
|
||||
sender = '"Ansible: %s" <root>' % host
|
||||
attach = res._task.action
|
||||
attach = res._task.action
|
||||
if 'invocation' in res._result:
|
||||
attach = "%s: %s" % (res._result['invocation']['module_name'], json.dumps(res._result['invocation']['module_args']))
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ __metaclass__ = type
|
||||
|
||||
import os
|
||||
|
||||
from ansible.constants import TREE_DIR
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
from ansible.utils.path import makedirs_safe
|
||||
from ansible.utils.unicode import to_bytes
|
||||
from ansible.constants import TREE_DIR
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
@@ -68,4 +68,3 @@ class CallbackModule(CallbackBase):
|
||||
|
||||
def v2_runner_on_unreachable(self, result):
|
||||
self.result_to_tree(result)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user