Mercurial > kallithea
changeset 7786:0f33c1da2fd5
kallithea-cli: set ssh_locale when creating .ini file so it doesn't have to be set manually before using ssh
The Python standard library does not seem to provide a simple way to
determine the current locale without calling locale.setlocale() and thus
potentially influencing the rest of the program.
Instead, try to determine the locale based on environment variables present
when 'kallithea-cli config-create' is run, and use it to prepopulate the ini
file.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Mon, 01 Jul 2019 10:05:00 +0200 |
parents | b5b91e854308 |
children | efd088f7903b |
files | kallithea/bin/kallithea_cli_config.py kallithea/lib/locale.py kallithea/lib/paster_commands/template.ini.mako |
diffstat | 3 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/bin/kallithea_cli_config.py Fri Jul 19 01:12:35 2019 +0200 +++ b/kallithea/bin/kallithea_cli_config.py Mon Jul 01 10:05:00 2019 +0200 @@ -22,6 +22,7 @@ import mako.exceptions +import kallithea.lib.locale from kallithea.lib import inifile def show_defaults(ctx, param, value): @@ -64,6 +65,7 @@ 'git_hook_interpreter': sys.executable, 'user_home_path': os.path.expanduser('~'), 'kallithea_cli_path': cli_base.kallithea_cli_path, + 'ssh_locale': kallithea.lib.locale.get_current_locale(), } ini_settings = defaultdict(dict)
--- a/kallithea/lib/locale.py Fri Jul 19 01:12:35 2019 +0200 +++ b/kallithea/lib/locale.py Mon Jul 01 10:05:00 2019 +0200 @@ -35,3 +35,14 @@ log.error("Note: No locale setting found in environment variables - perhaps set LC_CTYPE to some value from 'locale -a', like 'C.UTF-8' or 'en_US.UTF-8'") return False return True + +def get_current_locale(): + """Return the current locale based on environment variables. + There does not seem to be a good (and functional) way to get it via Python. + """ + for var in ['LC_ALL', 'LC_CTYPE', 'LANG']: + val = os.environ.get(var) + if val: + log.debug('Determined current locale via environment variable %s (%s)', var, val) + return val + return None
--- a/kallithea/lib/paster_commands/template.ini.mako Fri Jul 19 01:12:35 2019 +0200 +++ b/kallithea/lib/paster_commands/template.ini.mako Mon Jul 01 10:05:00 2019 +0200 @@ -346,6 +346,9 @@ <%text>## settings, which may not be available on the server.</%text> <%text>## See `locale -a` for valid values on this system.</%text> #ssh_locale = C.UTF-8 +%if ssh_locale: +ssh_locale = ${ssh_locale} +%endif <%text>####################################</%text> <%text>### CELERY CONFIG ####</%text>