Changeset - 0e33880b2897
[Not reviewed]
default
0 1 0
Mads Kiilerich - 7 years ago 2018-09-22 22:20:34
mads@kiilerich.com
config: abort early if the environment doesn't allow Python to pass Unicode strings to the file system layer

Dulwich passes unicode paths to the file system layer and it will thus not work
if run with LC_ALL=C ... which is quite common for services.

Also try to detect different cases and give helpful error messages about what
environment variable could be changed to what.
1 file changed with 16 insertions and 0 deletions:
0 comments (0 inline, 0 general)
kallithea/config/app_cfg.py
Show inline comments
 
@@ -111,24 +111,40 @@ try:
 
    from tgext.debugbar import enable_debugbar
 
    import kajiki # only to check its existence
 
except ImportError:
 
    pass
 
else:
 
    base_config['renderers'].append('kajiki')
 
    enable_debugbar(base_config)
 

	
 

	
 
def setup_configuration(app):
 
    config = app.config
 

	
 
    # Verify that things work when Dulwich passes unicode paths to the file system layer.
 
    # Note: UTF-8 is preferred, but for example ISO-8859-1 or mbcs should also work under the right cirumstances.
 
    try:
 
        u'\xe9'.encode(sys.getfilesystemencoding()) # Test using é (é)
 
    except UnicodeEncodeError:
 
        log.error("Cannot encode Unicode paths to file system encoding %r", sys.getfilesystemencoding())
 
        for var in ['LC_CTYPE', 'LC_ALL', 'LANG']:
 
            if var in os.environ:
 
                val = os.environ[var]
 
                log.error("Note: Environment variable %s is %r - perhaps change it to some other value from 'locale -a', like 'C.UTF-8' or 'en_US.UTF-8'", var, val)
 
                break
 
        else:
 
            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'")
 
        log.error("Terminating ...")
 
        sys.exit(1)
 

	
 
    # Mercurial sets encoding at module import time, so we have to monkey patch it
 
    hgencoding = config.get('hgencoding')
 
    if hgencoding:
 
        mercurial.encoding.encoding = hgencoding
 

	
 
    if config.get('ignore_alembic_revision', False):
 
        log.warn('database alembic revision checking is disabled')
 
    else:
 
        dbconf = config['sqlalchemy.url']
 
        alembic_cfg = alembic.config.Config()
 
        alembic_cfg.set_main_option('script_location', 'kallithea:alembic')
 
        alembic_cfg.set_main_option('sqlalchemy.url', dbconf)
0 comments (0 inline, 0 general)