Skip to content

Commit fe1a7f4

Browse files
committed
hook improvements
1 parent f12c589 commit fe1a7f4

3 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎module/ConfigParser.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,13 @@ def saveConfig(self, config, filename):
235235
#----------------------------------------------------------------------
236236
def cast(self, typ, value):
237237
"""cast value to given format"""
238+
if type(value) not in (str, unicode):
239+
return value
240+
238241
if typ == "int":
239242
return int(value)
240243
elif typ == "bool":
241-
return True if value.lower() in ("true", "on", "an","yes") else False
244+
return True if value.lower() in ("1","true", "on", "an","yes") else False
242245
else:
243246
return value
244247

@@ -278,6 +281,9 @@ def get(self, section, option):
278281
#----------------------------------------------------------------------
279282
def set(self, section, option, value):
280283
"""set value"""
284+
285+
value = self.cast(self.config[section][option]["type"], value)
286+
281287
self.config[section][option]["value"] = value
282288
self.save()
283289

@@ -289,6 +295,9 @@ def getPlugin(self, plugin, option):
289295
#----------------------------------------------------------------------
290296
def setPlugin(self, plugin, option, value):
291297
"""sets a value for a plugin"""
298+
299+
value = self.cast(self.plugin[plugin][option]["type"], value)
300+
292301
self.plugin[plugin][option]["value"] = value
293302
self.save()
294303

‎module/HookManager.py‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ def createIndex(self):
4848
for pluginClass in self.core.pluginManager.getHookPlugins():
4949
try:
5050
#hookClass = getattr(plugin, plugin.__name__)
51-
#@TODO config parsing and deactivating
51+
5252
plugin = pluginClass(self.core)
53-
if plugin.isActivated():
54-
#@TODO better selection
53+
if plugin.getConfig("load"):
5554
plugins.append(plugin)
56-
self.log.info(_("%s activated") % pluginClass.__name__)
55+
self.log.info(_("%s loaded, activated %s") % (pluginClass.__name__, plugin.isActivated() ))
5756
except:
5857
self.log.warning(_("Failed activating %(name)s") % {"name":pluginClass.__name__})
5958
if self.core.debug:
@@ -64,37 +63,41 @@ def createIndex(self):
6463

6564
def periodical(self):
6665
for plugin in self.plugins:
67-
if plugin.lastCall + plugin.interval < time():
66+
if plugin.isActivated() and plugin.lastCall + plugin.interval < time():
6867
plugin.periodical()
6968
plugin.lastCall = time()
7069

7170
def coreReady(self):
7271
for plugin in self.plugins:
73-
plugin.coreReady()
72+
if plugin.isActivated():
73+
plugin.coreReady()
7474

7575
@lock
7676
def downloadStarts(self, pyfile):
7777

7878
for plugin in self.plugins:
79-
plugin.downloadStarts(pyfile)
79+
if plugin.isActivated():
80+
plugin.downloadStarts(pyfile)
8081

8182
@lock
8283
def downloadFinished(self, pyfile):
8384

8485
for plugin in self.plugins:
85-
if "downloadFinished" in plugin.__threaded__:
86-
self.startThread(plugin.downloadFinished, pyfile)
87-
else:
88-
plugin.downloadFinished(pyfile)
86+
if plugin.isActivated():
87+
if "downloadFinished" in plugin.__threaded__:
88+
self.startThread(plugin.downloadFinished, pyfile)
89+
else:
90+
plugin.downloadFinished(pyfile)
8991

9092
@lock
9193
def packageFinished(self, package):
9294

9395
for plugin in self.plugins:
94-
if "packageFinished" in plugin.__threaded__:
95-
self.startThread(plugin.packageFinished, pyfile)
96-
else:
97-
plugin.packageFinished(package)
96+
if plugin.isActivated():
97+
if "packageFinished" in plugin.__threaded__:
98+
self.startThread(plugin.packageFinished, pyfile)
99+
else:
100+
plugin.packageFinished(package)
98101

99102
@lock
100103
def beforeReconnecting(self, ip):
@@ -106,7 +109,8 @@ def beforeReconnecting(self, ip):
106109
def afterReconnecting(self, ip):
107110

108111
for plugin in self.plugins:
109-
plugin.afterReconnecting(ip)
112+
if plugin.isActivated():
113+
plugin.afterReconnecting(ip)
110114

111115
def startThread(self, function, pyfile):
112116
t = HookThread(self.core.threadManager, function, pyfile)

‎module/PluginManager.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ def parse(self, typ, folder, create=False, pattern=False):
131131
if config:
132132
config = [ [y.strip() for y in x.replace("'","").replace('"',"").replace(")","").split(",")] for x in config[0].split("(") if x.strip()]
133133

134+
if folder == "hooks":
135+
config.append( ["load", "bool", "Load on startup", True] )
136+
134137
for item in config:
135138
self.core.config.addPluginConfig([name]+item)
136139

0 commit comments

Comments
 (0)