From 4b75ae96097741576f5dacd4a366119e56501700 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 25 Jan 2013 18:43:53 +0100 Subject: fallback when no system locale can be retrieved --- pyload.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'pyload.py') diff --git a/pyload.py b/pyload.py index 43d091a36..cc5295860 100755 --- a/pyload.py +++ b/pyload.py @@ -500,15 +500,21 @@ class Core(object): def init_logger(self, level): console = logging.StreamHandler(sys.stdout) - # change current locale to default if it is not set - current_locale = locale.getlocale() - if current_locale == (None, None): - current_locale = locale.setlocale(locale.LC_ALL, '') - - # We use timeformat provided by locale when available - if current_locale != (None, None): - tfrm = locale.nl_langinfo(locale.D_FMT) + " " + locale.nl_langinfo(locale.T_FMT) - else: # normally this case should not be entered + # try to get a time formatting depending on system locale + tfrm = None + try: # change current locale to default if it is not set + current_locale = locale.getlocale() + if current_locale == (None, None): + current_locale = locale.setlocale(locale.LC_ALL, '') + + # We use timeformat provided by locale when available + if current_locale != (None, None): + tfrm = locale.nl_langinfo(locale.D_FMT) + " " + locale.nl_langinfo(locale.T_FMT) + except: # something did go wrong, locale is heavily platform dependant + pass + + # default formatting when no ne was obtained + if not tfrm: tfrm = "%d.%m.%Y %H:%M:%S" frm = logging.Formatter("%(asctime)s %(levelname)-8s %(message)s", tfrm) -- cgit v1.2.3