Event fixes
This commit is contained in:
1 parent
e4588a5e7e
commit
cfadd851bf
14 files changed
+115
-98
No files matched your search
@@ -70,7 +70,7 @@ class Core(Plugin):
|
||||
|
||||
def crappyShutdown(self):
|
||||
try:
|
||||
self.urlopen('%sapp.shutdown' % self.createApiUrl(), show_error = False)
|
||||
self.urlopen('%s/app.shutdown' % self.createApiUrl(), show_error = False)
|
||||
return True
|
||||
except:
|
||||
self.initShutdown()
|
||||
@@ -78,7 +78,7 @@ class Core(Plugin):
|
||||
|
||||
def crappyRestart(self):
|
||||
try:
|
||||
self.urlopen('%sapp.restart' % self.createApiUrl(), show_error = False)
|
||||
self.urlopen('%s/app.restart' % self.createApiUrl(), show_error = False)
|
||||
return True
|
||||
except:
|
||||
self.initShutdown(restart = True)
|
||||
@@ -163,8 +163,7 @@ class Core(Plugin):
|
||||
host = 'localhost'
|
||||
port = Env.setting('port')
|
||||
|
||||
return '%s:%d' % (cleanHost(host).rstrip('/'), int(port))
|
||||
return '%s:%d%s' % (cleanHost(host).rstrip('/'), int(port), '/' + Env.setting('url_base').lstrip('/') if Env.setting('url_base') else '')
|
||||
|
||||
def createApiUrl(self):
|
||||
|
||||
return '%s/%s/' % (self.createBaseUrl(), Env.setting('api_key'))
|
||||
return '%s/%s' % (self.createBaseUrl(), Env.setting('api_key'))
|
||||
@@ -17,7 +17,7 @@ def requires_auth(f):
|
||||
@wraps(f)
|
||||
def decorated(*args, **kwargs):
|
||||
auth = getattr(request, 'authorization')
|
||||
if Env.setting('username') and (not auth or not check_auth(auth.username, md5(auth.password))):
|
||||
if Env.setting('username') and Env.setting('password') and (not auth or not check_auth(auth.username, md5(auth.password))):
|
||||
return authenticate()
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
@@ -2,6 +2,7 @@ from axl.axel import Event
|
||||
from couchpotato.core.helpers.variable import mergeDicts
|
||||
from couchpotato.core.logger import CPLog
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
|
||||
log = CPLog(__name__)
|
||||
@@ -25,15 +26,17 @@ def addEvent(name, handler, priority = 100):
|
||||
|
||||
try:
|
||||
parent = handler.im_self
|
||||
parent.beforeCall(handler)
|
||||
bc = hasattr(parent, 'beforeCall')
|
||||
if bc: parent.beforeCall(handler)
|
||||
h = runHandler(name, handler, *args, **kwargs)
|
||||
parent.afterCall(handler)
|
||||
ac = hasattr(parent, 'afterCall')
|
||||
if ac: parent.afterCall(handler)
|
||||
except:
|
||||
h = runHandler(name, handler, *args, **kwargs)
|
||||
|
||||
return h
|
||||
|
||||
e.handle(createHandle, priority = priority)
|
||||
e.handle(handler, priority = priority)
|
||||
|
||||
def removeEvent(name, handler):
|
||||
e = events[name]
|
||||
@@ -64,8 +67,10 @@ def fireEvent(name, *args, **kwargs):
|
||||
except: pass
|
||||
|
||||
e = events[name]
|
||||
e.lock.acquire()
|
||||
e.asynchronous = False
|
||||
result = e(*args, **kwargs)
|
||||
e.lock.release()
|
||||
|
||||
if single and not merge:
|
||||
results = None
|
||||
@@ -123,10 +128,11 @@ def fireEventAsync(name, *args, **kwargs):
|
||||
#log.debug('Async "%s": %s, %s' % (name, args, kwargs))
|
||||
try:
|
||||
e = events[name]
|
||||
e.lock.acquire()
|
||||
e.asynchronous = True
|
||||
e.error_handler = errorHandler
|
||||
|
||||
e(*args, **kwargs)
|
||||
e.lock.release()
|
||||
return True
|
||||
except Exception, e:
|
||||
log.error('%s: %s' % (name, e))
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
from couchpotato.core.event import fireEvent
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.notifications.base import Notification
|
||||
from gntp import notifier
|
||||
import logging
|
||||
import thread
|
||||
import time
|
||||
import traceback
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -15,13 +19,19 @@ class Growl(Notification):
|
||||
logger.disabled = True
|
||||
|
||||
try:
|
||||
self.growl = notifier.GrowlNotifier(
|
||||
applicationName = 'CouchPotato',
|
||||
notifications = ["Updates"],
|
||||
defaultNotifications = ["Updates"],
|
||||
applicationIcon = 'http://couchpota.to/media/images/couch.png',
|
||||
)
|
||||
self.growl.register()
|
||||
def startGrowl():
|
||||
time.sleep(2)
|
||||
try:
|
||||
self.growl = notifier.GrowlNotifier(
|
||||
applicationName = 'CouchPotato',
|
||||
notifications = ["Updates"],
|
||||
defaultNotifications = ["Updates"],
|
||||
applicationIcon = '%s/static/images/couch.png' % fireEvent('app.api_url', single = True),
|
||||
)
|
||||
self.growl.register()
|
||||
except:
|
||||
log.error('Failed register of growl: %s' % traceback.format_exc())
|
||||
thread.start_new_thread(startGrowl, ())
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class Plugin(object):
|
||||
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', self.__class__.__name__)
|
||||
class_name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
|
||||
|
||||
path = 'static/' + class_name + '/'
|
||||
path = '%s/static/%s/' % (Env.setting('api_key'), class_name)
|
||||
addView(path + '<path:filename>', self.showStatic, static = True)
|
||||
|
||||
if add_to_head:
|
||||
@@ -94,8 +94,6 @@ class Plugin(object):
|
||||
# http request
|
||||
def urlopen(self, url, timeout = 10, params = {}, headers = {}, multipart = False, show_error = True):
|
||||
|
||||
socket.setdefaulttimeout(timeout)
|
||||
|
||||
# Fill in some headers
|
||||
if not headers.get('Referer'):
|
||||
headers['Referer'] = urlparse(url).hostname
|
||||
@@ -114,13 +112,13 @@ class Plugin(object):
|
||||
cookies = cookielib.CookieJar()
|
||||
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies), MultipartPostHandler)
|
||||
|
||||
data = opener.open(request).read()
|
||||
data = opener.open(request, timeout = timeout).read()
|
||||
else:
|
||||
log.info('Opening url: %s, params: %s' % (url, [x for x in params.iterkeys()]))
|
||||
data = urllib.urlencode(params) if len(params) > 0 else None
|
||||
request = urllib2.Request(url, data, headers)
|
||||
|
||||
data = urllib2.urlopen(request).read()
|
||||
data = urllib2.urlopen(request, timeout = timeout).read()
|
||||
except IOError:
|
||||
if show_error:
|
||||
log.error('Failed opening url in %s: %s %s' % (self.getName(), url, traceback.format_exc(1)))
|
||||
|
||||
@@ -290,11 +290,11 @@ class Renamer(Plugin):
|
||||
|
||||
# Remove files
|
||||
for src in remove_files:
|
||||
log.info('Removing "%s"' % src)
|
||||
log.info('(fake) Removing "%s"' % src)
|
||||
|
||||
# Remove matching releases
|
||||
for release in remove_releases:
|
||||
log.info('Removing release %s' % release)
|
||||
log.info('(fake) Removing release %s' % release)
|
||||
|
||||
# Search for trailers etc
|
||||
fireEventAsync('renamer.after', group)
|
||||
|
||||
@@ -528,7 +528,9 @@ class Scanner(Plugin):
|
||||
return True
|
||||
|
||||
def isSampleFile(self, filename):
|
||||
return re.search('(^|[\W_])sample\d*[\W_]', filename.lower())
|
||||
is_sample = re.search('(^|[\W_])sample\d*[\W_]', filename.lower())
|
||||
if is_sample: log.debug('Is sample file: %s' % filename)
|
||||
return is_sample
|
||||
|
||||
def filesizeBetween(self, file, min = 0, max = 100000):
|
||||
try:
|
||||
|
||||
@@ -16,18 +16,18 @@ log = CPLog(__name__)
|
||||
class Searcher(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
addEvent('searcher.all', self.all)
|
||||
addEvent('searcher.all', self.all_movies)
|
||||
addEvent('searcher.single', self.single)
|
||||
addEvent('searcher.correct_movie', self.correctMovie)
|
||||
addEvent('searcher.download', self.download)
|
||||
|
||||
# Schedule cronjob
|
||||
fireEvent('schedule.cron', 'searcher.all', self.all, day = self.conf('cron_day'), hour = self.conf('cron_hour'), minute = self.conf('cron_minute'))
|
||||
fireEvent('schedule.cron', 'searcher.all', self.all_movies, day = self.conf('cron_day'), hour = self.conf('cron_hour'), minute = self.conf('cron_minute'))
|
||||
|
||||
if not Env.setting('development'):
|
||||
addEvent('app.load', self.all)
|
||||
addEvent('app.load', self.all_movies)
|
||||
|
||||
def all(self):
|
||||
def all_movies(self):
|
||||
|
||||
db = get_session()
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import os.path
|
||||
import time
|
||||
|
||||
|
||||
class Settings():
|
||||
class Settings(object):
|
||||
|
||||
options = {}
|
||||
types = {}
|
||||
|
||||
Reference in new issue
Block a user