diff options
author | mkaay <mkaay@mkaay.de> | 2010-01-04 20:35:26 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2010-01-04 20:35:26 +0100 |
commit | 89acc0ff595f73956572c8892ccb860c06fba33a (patch) | |
tree | 6edad5f8e0ca153b186a182b63aa5a5de815fe05 /module/HookManager.py | |
parent | fixed webserver (diff) | |
download | pyload-89acc0ff595f73956572c8892ccb860c06fba33a.tar.xz |
added hook system
Diffstat (limited to 'module/HookManager.py')
-rw-r--r-- | module/HookManager.py | 73 |
1 files changed, 73 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. + + @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() |