From 89acc0ff595f73956572c8892ccb860c06fba33a Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 4 Jan 2010 20:35:26 +0100 Subject: added hook system --- module/HookManager.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 module/HookManager.py (limited to 'module/HookManager.py') diff --git a/module/HookManager.py b/module/HookManager.py new file mode 100644 index 000000000..a0caae728 --- /dev/null +++ b/module/HookManager.py @@ -0,0 +1,73 @@ +# -*- 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 . + + @author: mkaay + @interface-version: 0.1 +""" +import logging + +from os.path import basename, join +from glob import glob + +from threading import Lock + +class HookManager(): + def __init__(self, core): + self.core = core + self.logger = logging.getLogger("log") + self.plugins = [] + self.lock = Lock() + self.createIndex() + + def createIndex(self): + self.lock.acquire() + pluginFiles = glob(join(self.core.plugin_folder, "hooks", "*.py")) + plugins = [] + 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) + pluginClass = getattr(module, pluginName) + plugins.append(pluginClass(self.core)) + + self.logger.info("Installed Hook: %s" % pluginName) + self.plugins = plugins + self.lock.release() + + def downloadStarts(self, pyfile): + self.lock.acquire() + for plugin in self.plugins: + plugin.downloadStarts(pyfile) + self.lock.release() + + def downloadFinished(self, pyfile): + self.lock.acquire() + for plugin in self.plugins: + plugin.downloadFinished(pyfile) + self.lock.release() + + def beforeReconnecting(self, ip): + self.lock.acquire() + for plugin in self.plugins: + plugin.beforeReconnecting(ip) + self.lock.release() + + def afterReconnecting(self, ip): + self.lock.acquire() + for plugin in self.plugins: + plugin.afterReconnecting(ip) + self.lock.release() -- cgit v1.2.3 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 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'module/HookManager.py') 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 -- cgit v1.2.3 From 5274c296dc13cf91df804a537b8e2109d62b3d98 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sat, 9 Jan 2010 22:22:07 +0100 Subject: better hook config --- module/HookManager.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'module/HookManager.py') diff --git a/module/HookManager.py b/module/HookManager.py index d2196ec4f..dc96d6d45 100644 --- a/module/HookManager.py +++ b/module/HookManager.py @@ -24,15 +24,9 @@ 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() @@ -45,17 +39,13 @@ class HookManager(): for pluginFile in pluginFiles: pluginName = basename(pluginFile).replace(".py", "") if pluginName == "Hook" or pluginName == "__init__": - 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) + continue + module = __import__("module.plugins.hooks."+pluginName, globals(), locals(), [pluginName], -1) pluginClass = getattr(module, pluginName) - pluginLoaded = pluginClass(self.core) - pluginLoaded.setup() - plugins.append(pluginLoaded) + plugin = pluginClass(self.core) + plugin.readConfig() + if plugin.isActivated(): + plugins.append(plugin) self.logger.info("Installed Hook: %s" % pluginName) self.plugins = plugins -- cgit v1.2.3 From a1c1d16ab515373c6111724393a0b242e9bf32a4 Mon Sep 17 00:00:00 2001 From: spoob Date: Sun, 10 Jan 2010 03:22:04 +0100 Subject: dont import deactivated hooks --- module/HookManager.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'module/HookManager.py') diff --git a/module/HookManager.py b/module/HookManager.py index dc96d6d45..57b766201 100644 --- a/module/HookManager.py +++ b/module/HookManager.py @@ -19,6 +19,8 @@ """ import logging +from module.XMLConfigParser import XMLConfigParser + from os.path import basename, join from glob import glob @@ -27,6 +29,9 @@ from threading import Lock 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() @@ -38,16 +43,21 @@ class HookManager(): plugins = [] for pluginFile in pluginFiles: pluginName = basename(pluginFile).replace(".py", "") - if pluginName == "Hook" or pluginName == "__init__": - continue + if pluginName == "__init__": + continue + if pluginName in self.config.keys(): + if not self.config[pluginName]["activated"]: + self.logger.info("Deactivated %s" % pluginName) + 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) plugin = pluginClass(self.core) - plugin.readConfig() - if plugin.isActivated(): - plugins.append(plugin) - - self.logger.info("Installed Hook: %s" % pluginName) + plugin.setup() + plugins.append(plugin) + self.logger.info("Activated %s" % pluginName) + self.plugins = plugins self.lock.release() -- cgit v1.2.3 From 5448bace91d93bd499e89d9ca5496321b4dc816c Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 10 Jan 2010 21:29:01 +0100 Subject: fixed mp3convert --- module/HookManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/HookManager.py') diff --git a/module/HookManager.py b/module/HookManager.py index 57b766201..3a1a3d533 100644 --- a/module/HookManager.py +++ b/module/HookManager.py @@ -54,7 +54,7 @@ class HookManager(): module = __import__("module.plugins.hooks."+pluginName, globals(), locals(), [pluginName], -1) pluginClass = getattr(module, pluginName) plugin = pluginClass(self.core) - plugin.setup() + plugin.readConfig() plugins.append(plugin) self.logger.info("Activated %s" % pluginName) -- cgit v1.2.3 From 769f156ea822d4520620727dc1317224a02bdaaa Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 26 Jan 2010 21:23:16 +0100 Subject: extended script support --- module/HookManager.py | 71 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 9 deletions(-) (limited to 'module/HookManager.py') diff --git a/module/HookManager.py b/module/HookManager.py index 3a1a3d533..5dbf41936 100644 --- a/module/HookManager.py +++ b/module/HookManager.py @@ -17,28 +17,46 @@ @author: mkaay @interface-version: 0.1 """ +from glob import glob import logging +from os import listdir +from os.path import basename +from os.path import join +import subprocess +from threading import Lock from module.XMLConfigParser import XMLConfigParser -from os.path import basename, join -from glob import glob - -from threading import Lock - class HookManager(): def __init__(self, core): self.core = core - self.configParser = XMLConfigParser(join("module","config","plugin.xml")) + self.configParser = XMLConfigParser(join("module", "config", "plugin.xml")) self.configParser.loadData() self.config = self.configParser.getConfig() self.logger = logging.getLogger("log") self.plugins = [] + self.scripts = {} self.lock = Lock() self.createIndex() def createIndex(self): self.lock.acquire() + + f = lambda x: False if x.startswith("#") or x.endswith("~") else True + self.scripts = {} + + folder = join(self.core.path, "scripts") + + self.scripts['download_preparing'] = filter(f, listdir(join(folder, 'download_preparing'))) + self.scripts['download_finished'] = filter(f, listdir(join(folder, 'download_finished'))) + self.scripts['package_finished'] = filter(f, listdir(join(folder, 'package_finished'))) + self.scripts['before_reconnect'] = filter(f, listdir(join(folder, 'before_reconnect'))) + self.scripts['after_reconnect'] = filter(f, listdir(join(folder, 'after_reconnect'))) + + self.core.logger.info("Installed Scripts: %s" % str(self.scripts)) + + self.folder = folder + pluginFiles = glob(join(self.core.plugin_folder, "hooks", "*.py")) plugins = [] for pluginFile in pluginFiles: @@ -50,8 +68,8 @@ class HookManager(): self.logger.info("Deactivated %s" % pluginName) continue else: - self.configParser.set(pluginName, {"option": "activated", "type": "bool", "name": "Activated"}, True) - module = __import__("module.plugins.hooks."+pluginName, globals(), locals(), [pluginName], -1) + 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) plugin = pluginClass(self.core) plugin.readConfig() @@ -63,24 +81,59 @@ class HookManager(): def downloadStarts(self, pyfile): self.lock.acquire() + + for script in self.scripts['download_preparing']: + try: + out = subprocess.Popen([join(self.folder, 'download_preparing', script), pyfile.plugin.props['name'], pyfile.url], stdout=subprocess.PIPE) + out.wait() + except: + pass + for plugin in self.plugins: plugin.downloadStarts(pyfile) self.lock.release() def downloadFinished(self, pyfile): self.lock.acquire() + + for script in self.scripts['download_finished']: + try: + out = subprocess.Popen([join(self.folder, 'download_finished', script), pyfile.plugin.props['name'], pyfile.url, pyfile.status.name, \ + join(self.core.path,self.core.config['general']['download_folder'], pyfile.folder, pyfile.status.name)], stdout=subprocess.PIPE) + except: + pass + + for plugin in self.plugins: plugin.downloadFinished(pyfile) self.lock.release() - + + def packageFinished(self, pyfile, package): + raise NotImplementedError + def beforeReconnecting(self, ip): self.lock.acquire() + + for script in self.scripts['before_reconnect']: + try: + out = subprocess.Popen([join(self.folder, 'before_reconnect', script), ip], stdout=subprocess.PIPE) + out.wait() + except: + pass + for plugin in self.plugins: plugin.beforeReconnecting(ip) self.lock.release() def afterReconnecting(self, ip): self.lock.acquire() + + for script in self.scripts['after_reconnect']: + try: + out = subprocess.Popen([join(self.folder, 'download_preparing', script), ip], stdout=subprocess.PIPE) + except: + pass + for plugin in self.plugins: plugin.afterReconnecting(ip) self.lock.release() -- cgit v1.2.3 From 7223256dbcbcad79b5edf0f71f525264903607f9 Mon Sep 17 00:00:00 2001 From: spoob Date: Tue, 26 Jan 2010 22:10:09 +0100 Subject: Better Script Support --- module/HookManager.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'module/HookManager.py') diff --git a/module/HookManager.py b/module/HookManager.py index 5dbf41936..66a65acc8 100644 --- a/module/HookManager.py +++ b/module/HookManager.py @@ -43,17 +43,21 @@ class HookManager(): self.lock.acquire() f = lambda x: False if x.startswith("#") or x.endswith("~") else True - self.scripts = {} + self.scripts = {} folder = join(self.core.path, "scripts") - self.scripts['download_preparing'] = filter(f, listdir(join(folder, 'download_preparing'))) - self.scripts['download_finished'] = filter(f, listdir(join(folder, 'download_finished'))) - self.scripts['package_finished'] = filter(f, listdir(join(folder, 'package_finished'))) - self.scripts['before_reconnect'] = filter(f, listdir(join(folder, 'before_reconnect'))) + self.scripts['download_preparing'] = filter(f, listdir(join(folder, 'download_preparing'))) + self.scripts['download_finished'] = filter(f, listdir(join(folder, 'download_finished'))) + self.scripts['package_finished'] = filter(f, listdir(join(folder, 'package_finished'))) + self.scripts['before_reconnect'] = filter(f, listdir(join(folder, 'before_reconnect'))) self.scripts['after_reconnect'] = filter(f, listdir(join(folder, 'after_reconnect'))) - self.core.logger.info("Installed Scripts: %s" % str(self.scripts)) + for script_type, script_name in self.scripts.iteritems(): + if script_name != []: + self.logger.info("Installed %s Scripts: %s" % (script_type, ", ".join(script_name))) + + #~ self.core.logger.info("Installed Scripts: %s" % str(self.scripts)) self.folder = folder -- cgit v1.2.3 From ce184310fd592047d47de24287b20fee00a587cd Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 27 Jan 2010 14:52:42 +0100 Subject: moved script support to a new plugin --- module/HookManager.py | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) (limited to 'module/HookManager.py') diff --git a/module/HookManager.py b/module/HookManager.py index 66a65acc8..a283a7349 100644 --- a/module/HookManager.py +++ b/module/HookManager.py @@ -19,10 +19,8 @@ """ from glob import glob import logging -from os import listdir from os.path import basename from os.path import join -import subprocess from threading import Lock from module.XMLConfigParser import XMLConfigParser @@ -35,32 +33,12 @@ class HookManager(): self.config = self.configParser.getConfig() self.logger = logging.getLogger("log") self.plugins = [] - self.scripts = {} self.lock = Lock() self.createIndex() def createIndex(self): self.lock.acquire() - f = lambda x: False if x.startswith("#") or x.endswith("~") else True - self.scripts = {} - - folder = join(self.core.path, "scripts") - - self.scripts['download_preparing'] = filter(f, listdir(join(folder, 'download_preparing'))) - self.scripts['download_finished'] = filter(f, listdir(join(folder, 'download_finished'))) - self.scripts['package_finished'] = filter(f, listdir(join(folder, 'package_finished'))) - self.scripts['before_reconnect'] = filter(f, listdir(join(folder, 'before_reconnect'))) - self.scripts['after_reconnect'] = filter(f, listdir(join(folder, 'after_reconnect'))) - - for script_type, script_name in self.scripts.iteritems(): - if script_name != []: - self.logger.info("Installed %s Scripts: %s" % (script_type, ", ".join(script_name))) - - #~ self.core.logger.info("Installed Scripts: %s" % str(self.scripts)) - - self.folder = folder - pluginFiles = glob(join(self.core.plugin_folder, "hooks", "*.py")) plugins = [] for pluginFile in pluginFiles: @@ -86,13 +64,6 @@ class HookManager(): def downloadStarts(self, pyfile): self.lock.acquire() - for script in self.scripts['download_preparing']: - try: - out = subprocess.Popen([join(self.folder, 'download_preparing', script), pyfile.plugin.props['name'], pyfile.url], stdout=subprocess.PIPE) - out.wait() - except: - pass - for plugin in self.plugins: plugin.downloadStarts(pyfile) self.lock.release() @@ -100,14 +71,6 @@ class HookManager(): def downloadFinished(self, pyfile): self.lock.acquire() - for script in self.scripts['download_finished']: - try: - out = subprocess.Popen([join(self.folder, 'download_finished', script), pyfile.plugin.props['name'], pyfile.url, pyfile.status.name, \ - join(self.core.path,self.core.config['general']['download_folder'], pyfile.folder, pyfile.status.name)], stdout=subprocess.PIPE) - except: - pass - - for plugin in self.plugins: plugin.downloadFinished(pyfile) self.lock.release() @@ -118,13 +81,6 @@ class HookManager(): def beforeReconnecting(self, ip): self.lock.acquire() - for script in self.scripts['before_reconnect']: - try: - out = subprocess.Popen([join(self.folder, 'before_reconnect', script), ip], stdout=subprocess.PIPE) - out.wait() - except: - pass - for plugin in self.plugins: plugin.beforeReconnecting(ip) self.lock.release() @@ -132,12 +88,6 @@ class HookManager(): def afterReconnecting(self, ip): self.lock.acquire() - for script in self.scripts['after_reconnect']: - try: - out = subprocess.Popen([join(self.folder, 'download_preparing', script), ip], stdout=subprocess.PIPE) - except: - pass - for plugin in self.plugins: plugin.afterReconnecting(ip) self.lock.release() -- cgit v1.2.3