# HG changeset patch # User Thomas De Schampheleire # Date 1561968300 -7200 # 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 -r b5b91e854308 -r 0f33c1da2fd5 kallithea/bin/kallithea_cli_config.py --- 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) diff -r b5b91e854308 -r 0f33c1da2fd5 kallithea/lib/locale.py --- 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 diff -r b5b91e854308 -r 0f33c1da2fd5 kallithea/lib/paster_commands/template.ini.mako --- 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>## 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 ####