summaryrefslogtreecommitdiffstats
path: root/pyload
diff options
context:
space:
mode:
Diffstat (limited to 'pyload')
-rw-r--r--pyload/AddonManager.py3
-rw-r--r--pyload/PluginManager.py7
-rw-r--r--pyload/api/AddonApi.py2
-rw-r--r--pyload/interaction/EventManager.py10
-rw-r--r--pyload/plugins/Addon.py75
5 files changed, 42 insertions, 55 deletions
diff --git a/pyload/AddonManager.py b/pyload/AddonManager.py
index d2dd25edc..7935ff112 100644
--- a/pyload/AddonManager.py
+++ b/pyload/AddonManager.py
@@ -139,8 +139,7 @@ class AddonManager:
self.log.debug("Plugin deactivated: %s" % plugin)
#remove periodic call
- if addon.cb:
- self.log.debug("Removed callback %s" % self.core.scheduler.removeJob(addon.cb))
+ self.log.debug("Removed callback %s" % self.core.scheduler.removeJob(addon.cb))
del self.plugins[addon.__name__]
#remove event listener
diff --git a/pyload/PluginManager.py b/pyload/PluginManager.py
index 297c67823..b6e4ed977 100644
--- a/pyload/PluginManager.py
+++ b/pyload/PluginManager.py
@@ -66,7 +66,7 @@ class PluginManager:
def addMatcher(self, matcher, index=0):
""" Inserts matcher at given index, first position by default """
if not isinstance(matcher, PluginMatcher):
- raise TypeError("Expected type of PluginMatcher, got %s instead" % type(matcher))
+ raise TypeError("Expected type of PluginMatcher, got '%s' instead" % type(matcher))
if matcher in self.matcher:
self.matcher.remove(matcher)
@@ -103,8 +103,7 @@ class PluginManager:
self.history.insert(0, found)
continue
-
- # matcher won't go to history
+ # matcher are tried secondly, they won't go to history
for m in self.matcher:
match = m.matchURL(url)
if match and match[0] in res:
@@ -122,7 +121,7 @@ class PluginManager:
if plugin.re.match(url):
res[ptype].append((url, name))
self.history.insert(0, (ptype, name))
- del self.history[self.MATCH_HISTORY:] # cut down to size of 10
+ del self.history[self.MATCH_HISTORY:] # cut down to size
found = True
break
if found: break
diff --git a/pyload/api/AddonApi.py b/pyload/api/AddonApi.py
index 4ae686d2d..12d3170d7 100644
--- a/pyload/api/AddonApi.py
+++ b/pyload/api/AddonApi.py
@@ -5,6 +5,7 @@ from pyload.Api import Api, RequirePerm, Permission
from ApiComponent import ApiComponent
+
class AddonApi(ApiComponent):
""" Methods to interact with addons """
@@ -23,5 +24,6 @@ class AddonApi(ApiComponent):
"""
return self.core.addonManager.getInfo(plugin)
+
if Api.extend(AddonApi):
del AddonApi \ No newline at end of file
diff --git a/pyload/interaction/EventManager.py b/pyload/interaction/EventManager.py
index 8cc1e81d2..ce56b6463 100644
--- a/pyload/interaction/EventManager.py
+++ b/pyload/interaction/EventManager.py
@@ -57,13 +57,9 @@ class EventManager:
def dispatchEvent(self, event, *args, **kwargs):
"""dispatches event with args"""
- for f in self.events["event"]:
- try:
- f(event, *args, **kwargs)
- except Exception, e:
- self.log.warning("Error calling event handler %s: %s, %s, %s"
- % ("event", f, args, str(e)))
- self.core.print_exc()
+ # dispatch the meta event
+ if event != "event":
+ self.dispatchEvent("event", *(event,) + args, **kwargs)
if event in self.events:
for f in self.events[event]:
diff --git a/pyload/plugins/Addon.py b/pyload/plugins/Addon.py
index d0ddfbca4..c1a297d28 100644
--- a/pyload/plugins/Addon.py
+++ b/pyload/plugins/Addon.py
@@ -1,22 +1,5 @@
# -*- coding: utf-8 -*-
-"""
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- @author: RaNaN
-"""
-
from traceback import print_exc
#from functools import wraps
@@ -24,6 +7,7 @@ from pyload.utils import has_method, to_list
from Base import Base
+
def class_name(p):
return p.rpartition(".")[2]
@@ -33,11 +17,13 @@ def AddEventListener(event):
:param event: Name of event or list of them.
"""
+
class _klass(object):
def __new__(cls, f, *args, **kwargs):
for ev in to_list(event):
addonManager.addEventListener(class_name(f.__module__), f.func_name, ev)
return f
+
return _klass
@@ -50,6 +36,7 @@ def AddonHandler(desc, media=None):
"""
pass
+
def AddonInfo(desc):
""" Called to retrieve information about the current state.
Decorated method must return anything convertable into string.
@@ -58,14 +45,17 @@ def AddonInfo(desc):
"""
pass
+
def threaded(f):
""" Decorator to run method in a thread. """
#@wraps(f)
- def run(*args,**kwargs):
+ def run(*args, **kwargs):
addonManager.startThread(f, *args, **kwargs)
+
return run
+
class Addon(Base):
"""
Base class for addon plugins. Use @threaded decorator for all longer running tasks.
@@ -78,7 +68,7 @@ class Addon(Base):
event_map = None
#: periodic call interval in seconds
- interval = 60
+ interval = 0
def __init__(self, core, manager, user=None):
Base.__init__(self, core, user)
@@ -86,7 +76,7 @@ class Addon(Base):
#: Provide information in dict here, usable by API `getInfo`
self.info = None
- #: Callback of periodical job task, used by addonmanager
+ #: Callback of periodical job task, used by addonManager
self.cb = None
#: `AddonManager`
@@ -97,44 +87,45 @@ class Addon(Base):
for event, funcs in self.event_map.iteritems():
if type(funcs) in (list, tuple):
for f in funcs:
- self.evm.listenTo(event, getattr(self,f))
+ self.evm.listenTo(event, getattr(self, f))
else:
- self.evm.listenTo(event, getattr(self,funcs))
+ self.evm.listenTo(event, getattr(self, funcs))
#delete for various reasons
self.event_map = None
- self.initPeriodical()
self.init()
- def initPeriodical(self):
- if id(self.periodical) != id(getattr(Addon, periodical)):
- self.startPeriodical()
+ # start periodically if set
+ self.startPeriodical(self.interval, 0)
- def startPeriodical(self, interval=self.interval, wait=self.interval):
- if not self.cb and self.setInterval(interval, False):
- self.cb = self.core.scheduler.addJob(wait, self._periodical, threaded=False)
- return interval
- else:
+ def startPeriodical(self, interval, wait):
+ """ Starts the periodical calls with given interval. Older entries will be canceled.
+ :param interval: interval in seconds
+ :param wait: time to wait in seconds before periodically starts
+ :return: True if s
+ """
+ if interval < 1:
return False
+ # stop running callback
+ if self.cb:
+ self.stopPeriodical()
+
+ self.cb = self.core.scheduler.addJob(wait, self._periodical, threaded=False)
+ self.interval = interval
+ return True
+
def stopPeriodical(self):
+ """ Stops periodical call if existing
+ :return: True if the callback was stopped, false otherwise.
+ """
if self.cb and self.core.scheduler.removeJob(self.cb):
self.cb = None
return True
else:
return False
- def setInterval(self, interval, recount=False):
- if interval > 0:
- if recount:
- return self.stopPeriodical() and self.startPeriodical(interval)
- else:
- self.interval = interval
- return True
- else:
- return False
-
def _periodical(self):
try:
if self.isActivated(): self.periodical()
@@ -185,7 +176,7 @@ class Addon(Base):
# public events starts from here
def downloadPreparing(self, pyfile):
pass
-
+
def downloadFinished(self, pyfile):
pass