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 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 ''
+9 -3
View File
@@ -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
+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")
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
+2 -2
View File
@@ -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))