From ad532495edc4103129bf86b53dec81038babe063 Mon Sep 17 00:00:00 2001 From: spoob Date: Sat, 9 Jan 2010 22:05:15 +0100 Subject: Hooks Config Incomplete --- module/HookManager.py | 19 ++++++++++++++++--- module/XMLConfigParser.py | 7 +++---- module/config/core_default.xml | 1 + module/config/gui_default.xml | 1 + module/config/plugin_default.xml | 1 + module/plugins/hooks/Hook.py | 8 ++++---- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/module/HookManager.py b/module/HookManager.py index a0caae728..d2196ec4f 100644 --- a/module/HookManager.py +++ b/module/HookManager.py @@ -24,9 +24,15 @@ from glob import glob from threading import Lock +from module.XMLConfigParser import XMLConfigParser + + class HookManager(): def __init__(self, core): self.core = core + self.configParser = XMLConfigParser(join("module","config","plugin.xml")) + self.configParser.loadData() + self.config = self.configParser.getConfig() self.logger = logging.getLogger("log") self.plugins = [] self.lock = Lock() @@ -39,10 +45,17 @@ class HookManager(): for pluginFile in pluginFiles: pluginName = basename(pluginFile).replace(".py", "") if pluginName == "Hook" or pluginName == "__init__": - continue - module = __import__("module.plugins.hooks."+pluginName, globals(), locals(), [pluginName], -1) + continue + if pluginName in self.config.keys(): + if not self.config[pluginName]["activated"]: + continue + else: + self.configParser.set(pluginName, {"option": "activated", "type": "bool", "name": "Activated"}, True) + module = __import__("module.plugins.hooks." + pluginName, globals(), locals(), [pluginName], -1) pluginClass = getattr(module, pluginName) - plugins.append(pluginClass(self.core)) + pluginLoaded = pluginClass(self.core) + pluginLoaded.setup() + plugins.append(pluginLoaded) self.logger.info("Installed Hook: %s" % pluginName) self.plugins = plugins diff --git a/module/XMLConfigParser.py b/module/XMLConfigParser.py index 5f58c834b..678338b41 100644 --- a/module/XMLConfigParser.py +++ b/module/XMLConfigParser.py @@ -48,6 +48,7 @@ class XMLConfigParser(): if not self.xml.documentElement.getAttribute("version") == self.version: print "Cant Update %s" % self.file exit() #ok? + self.root = self.xml.documentElement self._read_config() def _copyConfig(self): @@ -115,7 +116,6 @@ class XMLConfigParser(): if opt.nodeType == opt.ELEMENT_NODE: if data["option"] == opt.tagName: replace = opt - self._setAttributes(node, data) text = self.xml.createTextNode(str(value)) if replace: replace.replaceChild(text, replace.firstChild) @@ -128,13 +128,12 @@ class XMLConfigParser(): newSection = self.xml.createElement(section) newSection.appendChild(newNode) root.appendChild(newSection) - self._setAttributes(newSection, data) + self._setAttributes(section, data) self.saveData() self.loadData() def _setAttributes(self, node, data): - node.setAttribute("name", node.tagName) - option = node.getElementsByTagName(data["option"])[0] + option = self.root.getElementsByTagName(node)[0].getElementsByTagName(data["option"])[0] option.setAttribute("name", data["name"]) option.setAttribute("type", data["type"]) try: diff --git a/module/config/core_default.xml b/module/config/core_default.xml index 07d4ddc1c..0d684890a 100644 --- a/module/config/core_default.xml +++ b/module/config/core_default.xml @@ -1,3 +1,4 @@ + 7227 diff --git a/module/config/gui_default.xml b/module/config/gui_default.xml index 9b6d75936..490af199e 100644 --- a/module/config/gui_default.xml +++ b/module/config/gui_default.xml @@ -1,3 +1,4 @@ + diff --git a/module/config/plugin_default.xml b/module/config/plugin_default.xml index 3f033fc04..773e4e46f 100644 --- a/module/config/plugin_default.xml +++ b/module/config/plugin_default.xml @@ -1,3 +1,4 @@ + diff --git a/module/plugins/hooks/Hook.py b/module/plugins/hooks/Hook.py index 739af3200..4b5f6751f 100644 --- a/module/plugins/hooks/Hook.py +++ b/module/plugins/hooks/Hook.py @@ -40,10 +40,10 @@ class Hook(): def readConfig(self): self.configParser.loadData() section = self.props['name'] - try: - self.config = self.configParser.getConfig()[section] - except: - self.setup() + #~ try: + #~ self.config = self.configParser.getConfig()[section] + #~ except: + #~ self.setup() def setup(self): pass -- cgit v1.2.3