mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #15813 from terminalmage/issue13878
Encode/Decode unicode characters in cmd.run states
This commit is contained in:
commit
66ac56a0e0
@ -269,6 +269,12 @@ def _run(cmd,
|
||||
env_runas = json.loads(env_json).get('data', {})
|
||||
env_runas.update(env)
|
||||
env = env_runas
|
||||
# Encode unicode kwargs to filesystem encoding to avoid a
|
||||
# UnicodeEncodeError when the subprocess is invoked.
|
||||
fse = sys.getfilesystemencoding()
|
||||
for key, val in env.iteritems():
|
||||
if isinstance(val, unicode):
|
||||
env[key] = val.encode(fse)
|
||||
except ValueError:
|
||||
raise CommandExecutionError(
|
||||
'Environment could not be retrieved for User {0!r}'.format(
|
||||
|
@ -26,6 +26,7 @@ Example output::
|
||||
# Import python libs
|
||||
from numbers import Number
|
||||
import re
|
||||
import sys
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
@ -39,6 +40,7 @@ class NestDisplay(object):
|
||||
'''
|
||||
def __init__(self):
|
||||
self.colors = salt.utils.get_colors(__opts__.get('color'))
|
||||
self.fse = sys.getfilesystemencoding()
|
||||
|
||||
def display(self, ret, indent, prefix, out):
|
||||
'''
|
||||
@ -65,6 +67,10 @@ class NestDisplay(object):
|
||||
for line in lines:
|
||||
if strip_colors:
|
||||
line = salt.output.strip_esc_sequence(line)
|
||||
try:
|
||||
line = line.decode(self.fse)
|
||||
except AttributeError:
|
||||
pass
|
||||
out += u'{0}{1}{2}{3}{4}\n'.format(
|
||||
' ' * indent,
|
||||
self.colors['GREEN'],
|
||||
@ -90,6 +96,10 @@ class NestDisplay(object):
|
||||
'-' * 10,
|
||||
self.colors['ENDC'])
|
||||
for key in sorted(ret):
|
||||
try:
|
||||
key = key.decode(self.fse)
|
||||
except AttributeError:
|
||||
pass
|
||||
val = ret[key]
|
||||
out += u'{0}{1}{2}{3}{4}:\n'.format(
|
||||
' ' * indent,
|
||||
|
Loading…
Reference in New Issue
Block a user