mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
use append_if_not_found in locale.set_locale
This commit is contained in:
parent
e63260391c
commit
91c2d51400
1 changed files with 11 additions and 11 deletions
|
@ -128,13 +128,12 @@ def set_locale(locale):
|
|||
elif 'RedHat' in __grains__['os_family']:
|
||||
if not __salt__['file.file_exists']('/etc/sysconfig/i18n'):
|
||||
__salt__['file.touch']('/etc/sysconfig/i18n')
|
||||
if __salt__['cmd.retcode']('grep "^LANG=" /etc/sysconfig/i18n') != 0:
|
||||
__salt__['file.append']('/etc/sysconfig/i18n',
|
||||
'LANG="{0}"'.format(locale))
|
||||
else:
|
||||
__salt__['file.replace'](
|
||||
'/etc/sysconfig/i18n', '^LANG=.*', 'LANG="{0}"'.format(locale)
|
||||
)
|
||||
__salt__['file.replace'](
|
||||
'/etc/sysconfig/i18n',
|
||||
'^LANG=.*',
|
||||
'LANG="{0}"'.format(locale),
|
||||
append_if_not_found=True
|
||||
)
|
||||
elif 'Debian' in __grains__['os_family']:
|
||||
update_locale = salt.utils.which('update-locale')
|
||||
if update_locale is None:
|
||||
|
@ -142,12 +141,13 @@ def set_locale(locale):
|
|||
'Cannot set locale: "update-locale" was not found.')
|
||||
__salt__['cmd.run'](update_locale) # (re)generate /etc/default/locale
|
||||
|
||||
# FIXME: why are we writing to a file that is dynamically generated?
|
||||
__salt__['file.replace'](
|
||||
'/etc/default/locale', '^LANG=.*', 'LANG="{0}"'.format(locale)
|
||||
'/etc/default/locale',
|
||||
'^LANG=.*',
|
||||
'LANG="{0}"'.format(locale),
|
||||
append_if_not_found=True
|
||||
)
|
||||
if __salt__['cmd.retcode']('grep "^LANG=" /etc/default/locale') != 0:
|
||||
__salt__['file.append']('/etc/default/locale',
|
||||
'LANG="{0}"'.format(locale))
|
||||
elif 'Gentoo' in __grains__['os_family']:
|
||||
cmd = 'eselect --brief locale set {0}'.format(locale)
|
||||
return __salt__['cmd.retcode'](cmd, python_shell=False) == 0
|
||||
|
|
Loading…
Add table
Reference in a new issue