summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-07 15:26:52 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-07 15:26:52 +0200
commitfe1a7f4c91639588598c74a0c27a91192fbba78b (patch)
tree8c62519373956b1a621673375b706fd94dfa3d4c
parentreconnect fix (diff)
downloadpyload-fe1a7f4c91639588598c74a0c27a91192fbba78b.tar.xz
hook improvements
-rw-r--r--module/ConfigParser.py11
-rw-r--r--module/HookManager.py36
-rw-r--r--module/PluginManager.py3
3 files changed, 33 insertions, 17 deletions
diff --git a/module/ConfigParser.py b/module/ConfigParser.py
index 42dce1858..91396a83b 100644
--- a/module/ConfigParser.py
+++ b/module/ConfigParser.py
@@ -235,10 +235,13 @@ class ConfigParser:
#----------------------------------------------------------------------
def cast(self, typ, value):
"""cast value to given format"""
+ if type(value) not in (str, unicode):
+ return value
+
if typ == "int":
return int(value)
elif typ == "bool":
- return True if value.lower() in ("true", "on", "an","yes") else False
+ return True if value.lower() in ("1","true", "on", "an","yes") else False
else:
return value
@@ -278,6 +281,9 @@ class ConfigParser:
#----------------------------------------------------------------------
def set(self, section, option, value):
"""set value"""
+
+ value = self.cast(self.config[section][option]["type"], value)
+
self.config[section][option]["value"] = value
self.save()
@@ -289,6 +295,9 @@ class ConfigParser:
#----------------------------------------------------------------------
def setPlugin(self, plugin, option, value):
"""sets a value for a plugin"""
+
+ value = self.cast(self.plugin[plugin][option]["type"], value)
+
self.plugin[plugin][option]["value"] = value
self.save()
diff --git a/module/HookManager.py b/module/HookManager.py
index b188de1a6..503b9f77d 100644
--- a/module/HookManager.py
+++ b/module/HookManager.py
@@ -48,12 +48,11 @@ class HookManager():
for pluginClass in self.core.pluginManager.getHookPlugins():
try:
#hookClass = getattr(plugin, plugin.__name__)
- #@TODO config parsing and deactivating
+
plugin = pluginClass(self.core)
- if plugin.isActivated():
- #@TODO better selection
+ if plugin.getConfig("load"):
plugins.append(plugin)
- self.log.info(_("%s activated") % pluginClass.__name__)
+ self.log.info(_("%s loaded, activated %s") % (pluginClass.__name__, plugin.isActivated() ))
except:
self.log.warning(_("Failed activating %(name)s") % {"name":pluginClass.__name__})
if self.core.debug:
@@ -64,37 +63,41 @@ class HookManager():
def periodical(self):
for plugin in self.plugins:
- if plugin.lastCall + plugin.interval < time():
+ if plugin.isActivated() and plugin.lastCall + plugin.interval < time():
plugin.periodical()
plugin.lastCall = time()
def coreReady(self):
for plugin in self.plugins:
- plugin.coreReady()
+ if plugin.isActivated():
+ plugin.coreReady()
@lock
def downloadStarts(self, pyfile):
for plugin in self.plugins:
- plugin.downloadStarts(pyfile)
+ if plugin.isActivated():
+ plugin.downloadStarts(pyfile)
@lock
def downloadFinished(self, pyfile):
for plugin in self.plugins:
- if "downloadFinished" in plugin.__threaded__:
- self.startThread(plugin.downloadFinished, pyfile)
- else:
- plugin.downloadFinished(pyfile)
+ if plugin.isActivated():
+ if "downloadFinished" in plugin.__threaded__:
+ self.startThread(plugin.downloadFinished, pyfile)
+ else:
+ plugin.downloadFinished(pyfile)
@lock
def packageFinished(self, package):
for plugin in self.plugins:
- if "packageFinished" in plugin.__threaded__:
- self.startThread(plugin.packageFinished, pyfile)
- else:
- plugin.packageFinished(package)
+ if plugin.isActivated():
+ if "packageFinished" in plugin.__threaded__:
+ self.startThread(plugin.packageFinished, pyfile)
+ else:
+ plugin.packageFinished(package)
@lock
def beforeReconnecting(self, ip):
@@ -106,7 +109,8 @@ class HookManager():
def afterReconnecting(self, ip):
for plugin in self.plugins:
- plugin.afterReconnecting(ip)
+ if plugin.isActivated():
+ plugin.afterReconnecting(ip)
def startThread(self, function, pyfile):
t = HookThread(self.core.threadManager, function, pyfile)
diff --git a/module/PluginManager.py b/module/PluginManager.py
index 6815fed52..44a426d31 100644
--- a/module/PluginManager.py
+++ b/module/PluginManager.py
@@ -131,6 +131,9 @@ class PluginManager():
if config:
config = [ [y.strip() for y in x.replace("'","").replace('"',"").replace(")","").split(",")] for x in config[0].split("(") if x.strip()]
+ if folder == "hooks":
+ config.append( ["load", "bool", "Load on startup", True] )
+
for item in config:
self.core.config.addPluginConfig([name]+item)