Skip to content

Commit b798f33

Browse files
committed
Merge pull request saltstack#18655 from eliasp/2014.7-modules.locale-gentoo_fixes
2014.7 modules.locale gentoo fixes
2 parents 23259e5 + ea65712 commit b798f33

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

salt/modules/localemod.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ def set_locale(locale):
145145

146146

147147
def _normalize_locale(locale):
148+
# depending on the environment, the provided locale will also contain a charmap
149+
# (e.g. 'en_US.UTF-8 UTF-8' instead of only the locale 'en_US.UTF-8')
150+
# drop the charmap
151+
locale = locale.split()[0]
152+
148153
lang_encoding = locale.split('.')
149154
lang_split = lang_encoding[0].split('_')
150155
if len(lang_split) > 1:
@@ -183,16 +188,32 @@ def gen_locale(locale):
183188
184189
salt '*' locale.gen_locale 'en_US.UTF-8'
185190
'''
186-
if __grains__.get('os') == 'Debian':
191+
# validate the supplied locale
192+
valid = __salt__['file.replace'](
193+
'/usr/share/i18n/SUPPORTED',
194+
'^{0}$'.format(locale),
195+
'^{0}$'.format(locale),
196+
search_only=True
197+
)
198+
if not valid:
199+
log.error('The provided locale "{0}" is invalid'.format(locale))
200+
return False
201+
202+
if __grains__.get('os') == 'Debian' or __grains__.get('os_family') == 'Gentoo':
187203
__salt__['file.replace'](
188204
'/etc/locale.gen',
189205
'# {0} '.format(locale),
190206
'{0} '.format(locale),
191207
append_if_not_found=True
192208
)
193209

194-
__salt__['cmd.run'](
195-
'locale-gen {0}'.format(locale)
196-
)
210+
if __grains__.get('os_family') == 'Gentoo':
211+
return __salt__['cmd.retcode'](
212+
'locale-gen --generate "{0}"'.format(locale)
213+
)
214+
else:
215+
return __salt__['cmd.retcode'](
216+
'locale-gen "{0}"'.format(locale)
217+
)
197218

198-
return True
219+
return False

0 commit comments

Comments
 (0)