From ea3d91e34e646335860e571cbd23ee1008b58c25 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 14 Jan 2012 13:40:02 +0100 Subject: [PATCH] Add encoding to Env --- couchpotato/environment.py | 1 + couchpotato/runner.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/couchpotato/environment.py b/couchpotato/environment.py index 39adb3df..2a1fbeef 100644 --- a/couchpotato/environment.py +++ b/couchpotato/environment.py @@ -5,6 +5,7 @@ from couchpotato.core.settings import Settings class Env(object): ''' Environment variables ''' + _encoding = '' _uses_git = False _debug = False _settings = Settings() diff --git a/couchpotato/runner.py b/couchpotato/runner.py index 1c1eab1c..e63d1b05 100644 --- a/couchpotato/runner.py +++ b/couchpotato/runner.py @@ -5,6 +5,7 @@ from couchpotato.core.event import fireEventAsync, fireEvent from couchpotato.core.helpers.variable import getDataDir, tryInt from logging import handlers from werkzeug.contrib.cache import FileSystemCache +import locale import logging import os.path import socket @@ -61,8 +62,18 @@ def runCouchPotato(options, base_path, args, handle = None): if not os.path.isdir(log_dir): os.mkdir(log_dir) + try: + locale.setlocale(locale.LC_ALL, "") + encoding = locale.getpreferredencoding() + except (locale.Error, IOError): + pass + + # for OSes that are poorly configured I'll just force UTF-8 + if not encoding or encoding in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'): + encoding = 'UTF-8' # Register environment settings + Env.set('encoding', encoding) Env.set('uses_git', not options.nogit) Env.set('app_dir', base_path) Env.set('data_dir', data_dir)