Mercurial > kallithea
changeset 7377:0e33880b2897
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.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sat, 22 Sep 2018 22:20:34 +0200 |
parents | 6bd262eaa058 |
children | 415cc651bd83 |
files | kallithea/config/app_cfg.py |
diffstat | 1 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/config/app_cfg.py Tue Sep 18 20:57:32 2018 +0200 +++ b/kallithea/config/app_cfg.py Sat Sep 22 22:20:34 2018 +0200 @@ -120,6 +120,22 @@ 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: