From b79f02ab88a5ec59a6ec03d2d1a4bb7a0edc0a7a Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Mon, 14 May 2012 19:19:35 -0400 Subject: [PATCH] CC-3791: Media Monitor crash when there are media files with non-ascii name in watched folder --- python_apps/media-monitor/media_monitor.py | 10 +++++++++- python_apps/pypo/airtime-playout | 1 + python_apps/pypo/pypocli.py | 17 +++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/python_apps/media-monitor/media_monitor.py b/python_apps/media-monitor/media_monitor.py index a629e6718..2a4558191 100644 --- a/python_apps/media-monitor/media_monitor.py +++ b/python_apps/media-monitor/media_monitor.py @@ -8,6 +8,7 @@ import os import signal import traceback import locale +import re from configobj import ConfigObj @@ -47,7 +48,14 @@ def configure_locale(): else: new_locale = default_locale - logger.debug("New locale set to: " + locale.setlocale(locale.LC_ALL, new_locale)) + test = re.compile(r"UTF-?8", re.IGNORECASE) + if re.findall(new_locale): + logger.info("New locale set to: %s", locale.setlocale(locale.LC_ALL, new_locale)) + else: + logger.info("Invalid locale %s", new_locale) + sys.exit(1) + + reload(sys) sys.setdefaultencoding("UTF-8") diff --git a/python_apps/pypo/airtime-playout b/python_apps/pypo/airtime-playout index 05fbd20c4..101977596 100755 --- a/python_apps/pypo/airtime-playout +++ b/python_apps/pypo/airtime-playout @@ -14,6 +14,7 @@ exec 2>&1 export HOME="/var/tmp/airtime/pypo/" export PYTHONPATH=${api_client_path}:$PYTHONPATH +export LC_ALL=`cat /etc/default/locale | grep "LANG=" | cut -d= -f2 | tr -d "\n\""` # Note the -u when calling python! we need it to get unbuffered binary stdout and stderr exec python -u ${pypo_path}${pypo_script} > /var/log/airtime/pypo/py-interpreter.log 2>&1 diff --git a/python_apps/pypo/pypocli.py b/python_apps/pypo/pypocli.py index 0ef7e1927..b1c58fc88 100644 --- a/python_apps/pypo/pypocli.py +++ b/python_apps/pypo/pypocli.py @@ -11,6 +11,7 @@ import logging.config import logging.handlers import locale import os +import re from Queue import Queue from threading import Lock @@ -51,6 +52,7 @@ parser.add_option("-c", "--check", help="Check the cached schedule and exit", de #logging.captureWarnings(True) def configure_locale(): + logger.debug("Before %s", locale.nl_langinfo(locale.CODESET)) current_locale = locale.getlocale() if current_locale[1] is None: @@ -69,13 +71,24 @@ def configure_locale(): else: new_locale = default_locale - logger.debug("New locale set to: " + locale.setlocale(locale.LC_ALL, new_locale)) + test = re.compile(r"UTF-?8", re.IGNORECASE) + if re.findall(new_locale): + logger.info("New locale set to: %s", locale.setlocale(locale.LC_ALL, new_locale)) + else: + logger.info("Invalid locale %s", new_locale) + sys.exit(1) + + - + reload(sys) + sys.setdefaultencoding("UTF-8") current_locale_encoding = locale.getlocale()[1].lower() + logger.debug("sys default encoding %s", sys.getdefaultencoding()) + logger.debug("After %s", locale.nl_langinfo(locale.CODESET)) if current_locale_encoding not in ['utf-8', 'utf8']: logger.error("Need a UTF-8 locale. Currently '%s'. Exiting..." % current_locale_encoding) + sys.exit(1) # configure logging try: