From 8ac8a1a49c5a5bdfde60fbdc4fd209aecca4f3ca Mon Sep 17 00:00:00 2001 From: Ruud Date: Fri, 3 Feb 2012 17:25:56 +0100 Subject: [PATCH] Fixes --- couchpotato/core/_base/_core/main.py | 32 +++++++++++++----------- couchpotato/core/helpers/encoding.py | 12 ++++++--- couchpotato/core/plugins/base.py | 4 +-- couchpotato/core/plugins/scanner/main.py | 4 +-- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/couchpotato/core/_base/_core/main.py b/couchpotato/core/_base/_core/main.py index 5d89591e..007d1723 100644 --- a/couchpotato/core/_base/_core/main.py +++ b/couchpotato/core/_base/_core/main.py @@ -7,6 +7,7 @@ from couchpotato.core.plugins.base import Plugin from couchpotato.environment import Env from flask import request import os +import thread import time import traceback import webbrowser @@ -40,21 +41,24 @@ class Core(Plugin): def monitorParent(self): - do_shutdown = False - while 1 and not self.shuttingDown(): - if os.name == 'nt': - if os.getppid(os.getpid()) <= 1: - do_shutdown = True - break - else: - if os.getppid() <= 1: - do_shutdown = True - break - time.sleep(1) + def looping(): + do_shutdown = False + while 1 and not self.shuttingDown(): + if os.name == 'nt': + if os.getppid(os.getpid()) <= 1: + do_shutdown = True + break + else: + if os.getppid() <= 1: + do_shutdown = True + break + time.sleep(1) - if do_shutdown: - log.info('Starterscript has shutdown, shutdown subprocess') - fireEvent('app.crappy_shutdown') + if do_shutdown: + log.info('Starterscript has shutdown, shutdown subprocess') + fireEvent('app.crappy_shutdown') + + thread.start_new_thread(looping, ()) def md5Password(self, value): return md5(value) if value else '' diff --git a/couchpotato/core/helpers/encoding.py b/couchpotato/core/helpers/encoding.py index 7735904b..d252364f 100644 --- a/couchpotato/core/helpers/encoding.py +++ b/couchpotato/core/helpers/encoding.py @@ -22,11 +22,17 @@ def toUnicode(original, *args): if type(original) is unicode: return original else: - return unicode(original, *args) + try: + return unicode(original, *args) + except: + try: + return ek(original, *args) + except: + raise except UnicodeDecodeError: log.error('Unable to decode value: %s... ' % repr(original)[:20]) ascii_text = str(original).encode('string_escape') - return unicode(ascii_text) + return toUnicode(ascii_text) def ek(original, *args): if type(original) in [str, unicode]: @@ -34,7 +40,7 @@ def ek(original, *args): from couchpotato.environment import Env return original.decode(Env.get('encoding')) except UnicodeDecodeError: - return toUnicode(original, *args) + raise return original diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index 50948e8a..6648fdd0 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -173,7 +173,7 @@ class Plugin(object): log.error("Something went wrong when finishing the plugin function. Could not find the 'is_running' key") - def getCache(self, cache_key, url = None): + def getCache(self, cache_key, url = None, timeout = 300): cache = Env.get('cache').get(cache_key) if cache: if not Env.setting('development'): log.debug('Getting cache %s' % cache_key) @@ -182,7 +182,7 @@ class Plugin(object): if url: try: data = self.urlopen(url) - self.setCache(cache_key, data) + self.setCache(cache_key, data, timeout = timeout) return data except: pass diff --git a/couchpotato/core/plugins/scanner/main.py b/couchpotato/core/plugins/scanner/main.py index cede13c5..a1a02437 100644 --- a/couchpotato/core/plugins/scanner/main.py +++ b/couchpotato/core/plugins/scanner/main.py @@ -1,6 +1,6 @@ from couchpotato import get_session from couchpotato.core.event import fireEvent, addEvent -from couchpotato.core.helpers.encoding import toUnicode, simplifyString, ek +from couchpotato.core.helpers.encoding import toUnicode, simplifyString from couchpotato.core.helpers.variable import getExt, getImdb, tryInt from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin @@ -144,7 +144,7 @@ class Scanner(Plugin): # Scan all files of the folder if no files are set if len(files) == 0: files = [] - for root, dirs, walk_files in os.walk(ek(folder)): + for root, dirs, walk_files in os.walk(toUnicode(folder)): for filename in walk_files: files.append(os.path.join(root, filename))