Changeset - 0f33c1da2fd5
[Not reviewed]
default
0 3 0
Thomas De Schampheleire - 6 years ago 2019-07-01 10:05:00
thomas.de_schampheleire@nokia.com
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.
3 files changed with 16 insertions and 0 deletions:
0 comments (0 inline, 0 general)
kallithea/bin/kallithea_cli_config.py
Show inline comments
 
@@ -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)
 

	
kallithea/lib/locale.py
Show inline comments
 
@@ -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
kallithea/lib/paster_commands/template.ini.mako
Show inline comments
 
@@ -346,6 +346,9 @@ kallithea_cli_path = ${kallithea_cli_pat
 
<%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>
0 comments (0 inline, 0 general)