← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] ~smoser/cloud-init:feature/pregen-locale into cloud-init:master

 


Diff comments:

> diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
> index d06d46a..bcf45c6 100644
> --- a/cloudinit/distros/debian.py
> +++ b/cloudinit/distros/debian.py
> @@ -225,4 +217,36 @@ def _maybe_remove_legacy_eth0(path="/etc/network/interfaces.d/eth0.cfg"):
>  
>      LOG.warning(msg)
>  
> +
> +def apply_locale(locale, sys_path=LOCALE_CONF_FN, keyname='LANG'):
> +    """Apply the locale.
> +
> +    Run locale-gen for the provided locale and set the default
> +    system variable 'keyname' appropriately in the provided 'sys_path'.
> +
> +    If sys_path indicates that this value is already the default

I think you're saying:

If the system is already configured with a locale that matches the input value 'locale'
(and we check that by reading the value from sys_path)?

I think we should reword it, closer to match what you have in the commit message.

> +    ('keyname=locale') then no changes will be made and locale-gen not called.
> +    """
> +    if not locale:
> +        raise ValueError('Failed to provide locale value.')
> +
> +    if not sys_path:
> +        raise ValueError('Invalid path: %s' % sys_path)
> +
> +    if os.path.exists(sys_path):
> +        locale_content = util.load_file(sys_path)
> +        # if LANG isn't present, regen
> +        sys_defaults = util.load_shell_content(locale_content)
> +        sys_val = sys_defaults.get(keyname, "")
> +        if sys_val.lower() == locale.lower():
> +            LOG.debug(
> +                "System has '%s=%s' requested '%s', skipping regeneration.",
> +                keyname, sys_val, locale)
> +            return
> +
> +    util.subp(['locale-gen', locale], capture=False)
> +    util.subp(
> +        ['update-locale', '--locale-file=' + sys_path,
> +         '%s=%s' % (keyname, locale)], capture=False)
> +
>  # vi: ts=4 expandtab


-- 
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/327532
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:feature/pregen-locale into cloud-init:master.


References