summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-07-07 11:16:06 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-07-07 11:16:06 +0200
commit4344fb664864b157ac397ea210a7b34eaf3b275f (patch)
treee86a558f7cc6a15273b3aa3a0f5d474968316f28 /module/plugins
parentadditional log message (diff)
downloadpyload-4344fb664864b157ac397ea210a7b34eaf3b275f.tar.xz
basic event manager
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/Hook.py32
-rw-r--r--module/plugins/Plugin.py3
-rw-r--r--module/plugins/hooks/CaptchaTrader.py3
-rw-r--r--module/plugins/hooks/ExternalScripts.py5
-rw-r--r--module/plugins/hooks/IRCInterface.py4
-rw-r--r--module/plugins/hooks/XMPPInterface.py4
6 files changed, 38 insertions, 13 deletions
diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py
index 5e4b192ea..47faba95a 100644
--- a/module/plugins/Hook.py
+++ b/module/plugins/Hook.py
@@ -51,16 +51,36 @@ class Hook():
__description__ = """interface for hook"""
__author_name__ = ("mkaay", "RaNaN")
__author_mail__ = ("mkaay@mkaay.de", "RaNaN@pyload.org")
-
- def __init__(self, core):
+
+ #: automatically register event listeners for functions, attribute will be deleted dont use it yourself
+ event_map = None
+
+ #: periodic call interval in secondc
+ interval = 60
+
+ def __init__(self, core, manager):
self.core = core
self.log = core.log
self.config = core.config
-
- self.interval = 60 #: periodic call interval in seconds
- self.info = None #: Provide information in dict here, usable by API `getInfo`
-
+ #: Provide information in dict here, usable by API `getInfo`
+ self.info = None
+
+ #: `HookManager`
+ self.manager = manager
+
+ #register events
+ if self.event_map:
+ for event, funcs in self.event_map.iteritems():
+ if type(funcs) in (list, tuple):
+ for f in funcs:
+ self.manager.addEvent(event, getattr(self,f))
+ else:
+ self.manager.addEvent(event, getattr(self,funcs))
+
+ #delete for various reasons
+ self.event_map = None
+
self.setup()
def __repr__(self):
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index 71a06c8b5..ec8a0151a 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -450,6 +450,9 @@ class Plugin(object):
name = removeChars(name, '/\\"')
filename = join(location, fs_encode(name))
+
+ self.core.hookManager.dispatchEvent("downloadStarts", self.pyfile, url, filename)
+
try:
newname = self.req.httpDownload(url, filename, get=get, post=post, ref=ref, cookies=cookies,
chunks=self.getChunkCount(), resume=self.resumeDownload,
diff --git a/module/plugins/hooks/CaptchaTrader.py b/module/plugins/hooks/CaptchaTrader.py
index 2bae9401a..62ac2c8cc 100644
--- a/module/plugins/hooks/CaptchaTrader.py
+++ b/module/plugins/hooks/CaptchaTrader.py
@@ -58,6 +58,8 @@ class CaptchaTrader(Hook):
RESPOND_URL = "http://captchatrader.com/api/respond"
GETCREDITS_URL = "http://captchatrader.com/api/get_credits/username:%(user)s/password:%(password)s/"
+ def setup(self):
+ self.info = {}
def getCredits(self):
json = getURL(CaptchaTrader.GETCREDITS_URL % {"user": self.getConfig("username"),
@@ -67,6 +69,7 @@ class CaptchaTrader(Hook):
raise CaptchaTraderException(response[1])
else:
self.logInfo(_("%s credits left") % response[1])
+ self.info["credits"] = response[1]
return response[1]
def submit(self, captcha, captchaType="file", match=None):
diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py
index bbf5acde3..daffc1827 100644
--- a/module/plugins/hooks/ExternalScripts.py
+++ b/module/plugins/hooks/ExternalScripts.py
@@ -40,7 +40,6 @@ class ExternalScripts(Hook):
folders = ['download_preparing', 'download_finished', 'package_finished',
'before_reconnect', 'after_reconnect', 'unrar_finished']
-
for folder in folders:
self.scripts[folder] = []
@@ -52,6 +51,7 @@ class ExternalScripts(Hook):
if names:
self.logInfo(_("Installed scripts for %s : %s") % (script_type, ", ".join([basename(x) for x in names])))
+
def initPluginType(self, folder, path):
if not exists(path):
try:
@@ -91,8 +91,7 @@ class ExternalScripts(Hook):
def packageFinished(self, pypack):
for script in self.scripts['package_finished']:
folder = self.core.config['general']['download_folder']
- if self.core.config.get("general", "folder_per_package"):
- folder = save_join(folder. pypack.folder)
+ folder = save_join(folder. pypack.folder)
self.callScript(script, pypack.name, folder, pypack.id)
diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRCInterface.py
index 6fdb7622f..8be84f863 100644
--- a/module/plugins/hooks/IRCInterface.py
+++ b/module/plugins/hooks/IRCInterface.py
@@ -49,9 +49,9 @@ class IRCInterface(Thread, Hook):
__author_name__ = ("Jeix")
__author_mail__ = ("Jeix@hasnomail.com")
- def __init__(self, core):
+ def __init__(self, core, manager):
Thread.__init__(self)
- Hook.__init__(self, core)
+ Hook.__init__(self, core, manager)
self.setDaemon(True)
self.sm = core.server_methods
diff --git a/module/plugins/hooks/XMPPInterface.py b/module/plugins/hooks/XMPPInterface.py
index ce937c5d6..a96adf524 100644
--- a/module/plugins/hooks/XMPPInterface.py
+++ b/module/plugins/hooks/XMPPInterface.py
@@ -43,8 +43,8 @@ class XMPPInterface(IRCInterface, JabberClient):
implements(IMessageHandlersProvider)
- def __init__(self, core):
- IRCInterface.__init__(self, core)
+ def __init__(self, core, manager):
+ IRCInterface.__init__(self, core, manager)
self.jid = JID(self.getConfig("jid"))
password = self.getConfig("pw")