mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
diff can now be a list
This commit is contained in:
parent
13c91ef9d4
commit
c3372936aa
1 changed files with 34 additions and 28 deletions
|
@ -72,34 +72,40 @@ class CallbackBase:
|
||||||
for warning in res['warnings']:
|
for warning in res['warnings']:
|
||||||
self._display.warning(warning)
|
self._display.warning(warning)
|
||||||
|
|
||||||
def _get_diff(self, diff):
|
def _get_diff(self, difflist):
|
||||||
try:
|
|
||||||
with warnings.catch_warnings():
|
if not isinstance(difflist, list):
|
||||||
warnings.simplefilter('ignore')
|
difflist = [difflist]
|
||||||
ret = []
|
|
||||||
if 'dst_binary' in diff:
|
ret = []
|
||||||
ret.append("diff skipped: destination file appears to be binary\n")
|
for diff in difflist:
|
||||||
if 'src_binary' in diff:
|
try:
|
||||||
ret.append("diff skipped: source file appears to be binary\n")
|
with warnings.catch_warnings():
|
||||||
if 'dst_larger' in diff:
|
warnings.simplefilter('ignore')
|
||||||
ret.append("diff skipped: destination file size is greater than %d\n" % diff['dst_larger'])
|
ret = []
|
||||||
if 'src_larger' in diff:
|
if 'dst_binary' in diff:
|
||||||
ret.append("diff skipped: source file size is greater than %d\n" % diff['src_larger'])
|
ret.append("diff skipped: destination file appears to be binary\n")
|
||||||
if 'before' in diff and 'after' in diff:
|
if 'src_binary' in diff:
|
||||||
if 'before_header' in diff:
|
ret.append("diff skipped: source file appears to be binary\n")
|
||||||
before_header = "before: %s" % diff['before_header']
|
if 'dst_larger' in diff:
|
||||||
else:
|
ret.append("diff skipped: destination file size is greater than %d\n" % diff['dst_larger'])
|
||||||
before_header = 'before'
|
if 'src_larger' in diff:
|
||||||
if 'after_header' in diff:
|
ret.append("diff skipped: source file size is greater than %d\n" % diff['src_larger'])
|
||||||
after_header = "after: %s" % diff['after_header']
|
if 'before' in diff and 'after' in diff:
|
||||||
else:
|
if 'before_header' in diff:
|
||||||
after_header = 'after'
|
before_header = "before: %s" % diff['before_header']
|
||||||
differ = difflib.unified_diff(to_unicode(diff['before']).splitlines(True), to_unicode(diff['after']).splitlines(True), before_header, after_header, '', '', 10)
|
else:
|
||||||
for line in list(differ):
|
before_header = 'before'
|
||||||
ret.append(line)
|
if 'after_header' in diff:
|
||||||
return u"".join(ret)
|
after_header = "after: %s" % diff['after_header']
|
||||||
except UnicodeDecodeError:
|
else:
|
||||||
return ">> the files are different, but the diff library cannot compare unicode strings"
|
after_header = 'after'
|
||||||
|
differ = difflib.unified_diff(to_unicode(diff['before']).splitlines(True), to_unicode(diff['after']).splitlines(True), before_header, after_header, '', '', 10)
|
||||||
|
ret.extend(list(differ))
|
||||||
|
ret.append('\n')
|
||||||
|
return u"".join(ret)
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
ret.append(">> the files are different, but the diff library cannot compare unicode strings\n\n")
|
||||||
|
|
||||||
def _process_items(self, result):
|
def _process_items(self, result):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue