From a6f0ab31e4d4cff1a345ef00676df44298b049ab Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Wed, 19 Jun 2019 17:06:49 +0100 Subject: [PATCH] fw/entrypoint: Add check for system default encoding Check what the default encoding for the system is set to. If this is not configured to use 'UTF-8', log a warning to the user as this is known to cause issues when attempting to parse none ascii files during operation. --- wa/framework/entrypoint.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wa/framework/entrypoint.py b/wa/framework/entrypoint.py index b517fab6..7be724bc 100644 --- a/wa/framework/entrypoint.py +++ b/wa/framework/entrypoint.py @@ -16,6 +16,7 @@ import sys import argparse +import locale import logging import os import warnings @@ -76,6 +77,18 @@ def check_devlib_version(): raise HostError(msg.format(format_version(required_devlib_version), devlib.__version__)) +# If the default encoding is not UTF-8 warn the user as this may cause compatibility issues +# when parsing files. +def check_system_encoding(): + system_encoding = locale.getpreferredencoding() + msg = 'System Encoding: {}'.format(system_encoding) + if 'UTF-8' not in system_encoding: + logger.warning(msg) + logger.warning('To prevent encoding issues please use a locale setting which supports UTF-8') + else: + logger.debug(msg) + + def main(): if not os.path.exists(settings.user_directory): init_user_directory() @@ -115,6 +128,7 @@ def main(): logger.debug('devlib version: {}'.format(devlib.__full_version__)) logger.debug('Command Line: {}'.format(' '.join(sys.argv))) check_devlib_version() + check_system_encoding() # each command will add its own subparser subparsers = parser.add_subparsers(dest='command')