This commit is contained in:
Ruud
2012-02-03 17:25:56 +01:00
parent 9cc1679fb5
commit 8ac8a1a49c
4 changed files with 31 additions and 21 deletions
+18 -14
View File
@@ -7,6 +7,7 @@ from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env from couchpotato.environment import Env
from flask import request from flask import request
import os import os
import thread
import time import time
import traceback import traceback
import webbrowser import webbrowser
@@ -40,21 +41,24 @@ class Core(Plugin):
def monitorParent(self): def monitorParent(self):
do_shutdown = False def looping():
while 1 and not self.shuttingDown(): do_shutdown = False
if os.name == 'nt': while 1 and not self.shuttingDown():
if os.getppid(os.getpid()) <= 1: if os.name == 'nt':
do_shutdown = True if os.getppid(os.getpid()) <= 1:
break do_shutdown = True
else: break
if os.getppid() <= 1: else:
do_shutdown = True if os.getppid() <= 1:
break do_shutdown = True
time.sleep(1) break
time.sleep(1)
if do_shutdown: if do_shutdown:
log.info('Starterscript has shutdown, shutdown subprocess') log.info('Starterscript has shutdown, shutdown subprocess')
fireEvent('app.crappy_shutdown') fireEvent('app.crappy_shutdown')
thread.start_new_thread(looping, ())
def md5Password(self, value): def md5Password(self, value):
return md5(value) if value else '' return md5(value) if value else ''
+9 -3
View File
@@ -22,11 +22,17 @@ def toUnicode(original, *args):
if type(original) is unicode: if type(original) is unicode:
return original return original
else: else:
return unicode(original, *args) try:
return unicode(original, *args)
except:
try:
return ek(original, *args)
except:
raise
except UnicodeDecodeError: except UnicodeDecodeError:
log.error('Unable to decode value: %s... ' % repr(original)[:20]) log.error('Unable to decode value: %s... ' % repr(original)[:20])
ascii_text = str(original).encode('string_escape') ascii_text = str(original).encode('string_escape')
return unicode(ascii_text) return toUnicode(ascii_text)
def ek(original, *args): def ek(original, *args):
if type(original) in [str, unicode]: if type(original) in [str, unicode]:
@@ -34,7 +40,7 @@ def ek(original, *args):
from couchpotato.environment import Env from couchpotato.environment import Env
return original.decode(Env.get('encoding')) return original.decode(Env.get('encoding'))
except UnicodeDecodeError: except UnicodeDecodeError:
return toUnicode(original, *args) raise
return original return original
+2 -2
View File
@@ -173,7 +173,7 @@ class Plugin(object):
log.error("Something went wrong when finishing the plugin function. Could not find the 'is_running' key") 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) cache = Env.get('cache').get(cache_key)
if cache: if cache:
if not Env.setting('development'): log.debug('Getting cache %s' % cache_key) if not Env.setting('development'): log.debug('Getting cache %s' % cache_key)
@@ -182,7 +182,7 @@ class Plugin(object):
if url: if url:
try: try:
data = self.urlopen(url) data = self.urlopen(url)
self.setCache(cache_key, data) self.setCache(cache_key, data, timeout = timeout)
return data return data
except: except:
pass pass
+2 -2
View File
@@ -1,6 +1,6 @@
from couchpotato import get_session from couchpotato import get_session
from couchpotato.core.event import fireEvent, addEvent 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.helpers.variable import getExt, getImdb, tryInt
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin 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 # Scan all files of the folder if no files are set
if len(files) == 0: if len(files) == 0:
files = [] 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: for filename in walk_files:
files.append(os.path.join(root, filename)) files.append(os.path.join(root, filename))