# HG changeset patch # User Thomas De Schampheleire # Date 2019-07-01 10:05:00 # Node ID 0f33c1da2fd50ecd7565497876498b6941099ab4 # Parent b5b91e854308aa94cb26a47e76bbd3ce27dfd48f 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. diff --git a/kallithea/bin/kallithea_cli_config.py b/kallithea/bin/kallithea_cli_config.py --- a/kallithea/bin/kallithea_cli_config.py +++ b/kallithea/bin/kallithea_cli_config.py @@ -22,6 +22,7 @@ from collections import defaultdict import mako.exceptions +import kallithea.lib.locale from kallithea.lib import inifile def show_defaults(ctx, param, value): @@ -64,6 +65,7 @@ def config_create(config_file, key_value '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) diff --git a/kallithea/lib/locale.py b/kallithea/lib/locale.py --- a/kallithea/lib/locale.py +++ b/kallithea/lib/locale.py @@ -35,3 +35,14 @@ def current_locale_is_valid(): 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 diff --git a/kallithea/lib/paster_commands/template.ini.mako b/kallithea/lib/paster_commands/template.ini.mako --- a/kallithea/lib/paster_commands/template.ini.mako +++ b/kallithea/lib/paster_commands/template.ini.mako @@ -346,6 +346,9 @@ kallithea_cli_path = ${kallithea_cli_pat <%text>## settings, which may not be available on the server. <%text>## See `locale -a` for valid values on this system. #ssh_locale = C.UTF-8 +%if ssh_locale: +ssh_locale = ${ssh_locale} +%endif <%text>#################################### <%text>### CELERY CONFIG ####