Show a nicer message when attempting to diff unicode files.
This commit is contained in:
parent
18cbb64f25
commit
61d01f549f
1 changed files with 11 additions and 3 deletions
|
@ -35,6 +35,7 @@ import tty
|
||||||
import pipes
|
import pipes
|
||||||
import random
|
import random
|
||||||
import difflib
|
import difflib
|
||||||
|
import warnings
|
||||||
|
|
||||||
VERBOSITY=0
|
VERBOSITY=0
|
||||||
|
|
||||||
|
@ -619,9 +620,16 @@ def make_sudo_cmd(sudo_user, executable, cmd):
|
||||||
prompt, sudo_user, executable or '$SHELL', pipes.quote(cmd))
|
prompt, sudo_user, executable or '$SHELL', pipes.quote(cmd))
|
||||||
return ('/bin/sh -c ' + pipes.quote(sudocmd), prompt)
|
return ('/bin/sh -c ' + pipes.quote(sudocmd), prompt)
|
||||||
|
|
||||||
def get_diff(before_string, after_string):
|
def get_diff(before, after):
|
||||||
# called by --diff usage in playbook and runner via callbacks
|
# called by --diff usage in playbook and runner via callbacks
|
||||||
# include names in diffs 'before' and 'after' and do diff -U 10
|
# include names in diffs 'before' and 'after' and do diff -U 10
|
||||||
differ = difflib.unified_diff(before_string.split("\n"), after_string.split("\n"), 'before', 'after', '', '', 10)
|
|
||||||
return "\n".join(list(differ))
|
try:
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.simplefilter('ignore')
|
||||||
|
differ = difflib.unified_diff(before.split("\n"), after.split("\n"), 'before', 'after', '', '', 10)
|
||||||
|
return "\n".join(list(differ))
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
return ">> the files are different, but the diff library cannot compare unicode strings"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue