mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Merge pull request #12133 from fivethreeo/develop
New locale modules and states
This commit is contained in:
commit
207423f869
@ -142,3 +142,50 @@ def set_locale(locale):
|
||||
return __salt__['cmd.retcode'](cmd) == 0
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _normalize_locale(locale):
|
||||
lang_encoding = locale.split('.')
|
||||
lang_split = lang_encoding[0].split('_')
|
||||
if len(lang_split) > 1:
|
||||
lang_split[1] = lang_split[1].upper()
|
||||
lang_encoding[0] = '_'.join(lang_split)
|
||||
if len(lang_encoding) > 1:
|
||||
if len(lang_split) > 1:
|
||||
lang_encoding[1] = lang_encoding[1].lower().replace('-', '')
|
||||
return '.'.join(lang_encoding)
|
||||
|
||||
|
||||
def avail(locale):
|
||||
'''
|
||||
Check if a locale is available
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' locale.avail 'en_US.UTF-8'
|
||||
'''
|
||||
normalized_locale = _normalize_locale(locale)
|
||||
avail_locales = __salt__['locale.list_avail']()
|
||||
locale_exists = next((True for x in avail_locales
|
||||
if _normalize_locale(x.strip()) == normalized_locale), False)
|
||||
return locale_exists
|
||||
|
||||
|
||||
def gen_locale(locale):
|
||||
'''
|
||||
Generate a locale
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' locale.gen_locale 'en_US.UTF-8'
|
||||
'''
|
||||
|
||||
__salt__['cmd.run'](
|
||||
'locale-gen {0}'.format(locale)
|
||||
)
|
||||
|
||||
return True
|
||||
|
@ -44,5 +44,34 @@ def system(name):
|
||||
return ret
|
||||
else:
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Failed to set system locale'
|
||||
ret['comment'] = 'Failed to set system locale to {0}'.format(name)
|
||||
return ret
|
||||
|
||||
|
||||
def present(name):
|
||||
'''
|
||||
Generate a locale if it is not present
|
||||
|
||||
name
|
||||
The name of the locale to be present
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': None,
|
||||
'comment': ''}
|
||||
if __salt__['locale.avail'](name):
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Locale {0} is already present'.format(name)
|
||||
return ret
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'Locale {0} needs to be generated'.format(name)
|
||||
return ret
|
||||
if __salt__['locale.gen_locale'](name):
|
||||
ret['changes'] = {'locale': name}
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Generated locale {0}'.format(name)
|
||||
return ret
|
||||
else:
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Failed to generate locale {0}'.format(name)
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user