mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Update unicode changes with proper list handling in open files
This commit is contained in:
parent
9effd08bb3
commit
0dc7345102
@ -11,6 +11,7 @@ import os
|
|||||||
# Import salt libs
|
# Import salt libs
|
||||||
from salt.ext import six
|
from salt.ext import six
|
||||||
from salt.ext.six.moves import range
|
from salt.ext.six.moves import range
|
||||||
|
import salt.utils.data
|
||||||
import salt.utils.files
|
import salt.utils.files
|
||||||
import salt.utils.functools
|
import salt.utils.functools
|
||||||
import salt.utils.stringutils
|
import salt.utils.stringutils
|
||||||
@ -104,8 +105,8 @@ def _write_incron_lines(user, lines):
|
|||||||
return ret
|
return ret
|
||||||
else:
|
else:
|
||||||
path = salt.utils.files.mkstemp()
|
path = salt.utils.files.mkstemp()
|
||||||
with salt.utils.files.fopen(path, 'w+') as fp_:
|
with salt.utils.files.fopen(path, 'wb') as fp_:
|
||||||
fp_.writelines(salt.utils.stringutils.to_str(lines))
|
fp_.writelines(salt.utils.data.encode(lines))
|
||||||
if __grains__['os_family'] == 'Solaris' and user != "root":
|
if __grains__['os_family'] == 'Solaris' and user != "root":
|
||||||
__salt__['cmd.run']('chown {0} {1}'.format(user, path), python_shell=False)
|
__salt__['cmd.run']('chown {0} {1}'.format(user, path), python_shell=False)
|
||||||
ret = __salt__['cmd.run_all'](_get_incron_cmdstr(path), runas=user, python_shell=False)
|
ret = __salt__['cmd.run_all'](_get_incron_cmdstr(path), runas=user, python_shell=False)
|
||||||
@ -119,7 +120,7 @@ def _write_file(folder, filename, data):
|
|||||||
'''
|
'''
|
||||||
path = os.path.join(folder, filename)
|
path = os.path.join(folder, filename)
|
||||||
if not os.path.exists(folder):
|
if not os.path.exists(folder):
|
||||||
msg = '%s cannot be written. %s does not exist', filename, folder
|
msg = '{0} cannot be written. {1} does not exist'.format(filename, folder)
|
||||||
log.error(msg)
|
log.error(msg)
|
||||||
raise AttributeError(six.text_type(msg))
|
raise AttributeError(six.text_type(msg))
|
||||||
with salt.utils.files.fopen(path, 'w') as fp_:
|
with salt.utils.files.fopen(path, 'w') as fp_:
|
||||||
@ -135,7 +136,7 @@ def _read_file(folder, filename):
|
|||||||
path = os.path.join(folder, filename)
|
path = os.path.join(folder, filename)
|
||||||
try:
|
try:
|
||||||
with salt.utils.files.fopen(path, 'rb') as contents:
|
with salt.utils.files.fopen(path, 'rb') as contents:
|
||||||
return salt.utils.stringutils.to_unicode(contents.readlines())
|
return salt.utils.data.decode(contents.readlines())
|
||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
# Import Salt libs
|
# Import Salt libs
|
||||||
|
import salt.utils.data
|
||||||
import salt.utils.files
|
import salt.utils.files
|
||||||
import salt.utils.json
|
import salt.utils.json
|
||||||
import salt.utils.stringutils
|
import salt.utils.stringutils
|
||||||
@ -395,10 +396,10 @@ class _Ini(_Section):
|
|||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
try:
|
try:
|
||||||
with salt.utils.files.fopen(self.name, 'w') as outfile:
|
with salt.utils.files.fopen(self.name, 'wb') as outfile:
|
||||||
ini_gen = self.gen_ini()
|
ini_gen = self.gen_ini()
|
||||||
next(ini_gen)
|
next(ini_gen)
|
||||||
outfile.writelines(salt.utils.stringutils.to_str(ini_gen))
|
outfile.writelines(salt.utils.data.encode(ini_gen))
|
||||||
except (OSError, IOError) as exc:
|
except (OSError, IOError) as exc:
|
||||||
raise CommandExecutionError(
|
raise CommandExecutionError(
|
||||||
"Unable to write file '{0}'. "
|
"Unable to write file '{0}'. "
|
||||||
|
Loading…
Reference in New Issue
Block a user