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 ---------------- module/plugins/hooks/ExternalScripts.py | 100 ++++++++++++++++++++++++++++++++ pyLoadCore.py | 4 -- 3 files changed, 100 insertions(+), 54 deletions(-) create mode 100644 module/plugins/hooks/ExternalScripts.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() diff --git a/module/plugins/hooks/ExternalScripts.py b/module/plugins/hooks/ExternalScripts.py new file mode 100644 index 000000000..004ba07cc --- /dev/null +++ b/module/plugins/hooks/ExternalScripts.py @@ -0,0 +1,100 @@ +# -*- 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 +""" + +from module.plugins.hooks.Hook import Hook +import subprocess +from os import listdir, sep +from os.path import join + +class ExternalScripts(Hook): + def __init__(self, core): + Hook.__init__(self, core) + props = {} + props['name'] = "ExternalScripts" + props['version'] = "0.1" + props['description'] = """run external scripts""" + props['author_name'] = ("mkaay", "RaNaN", "spoob") + props['author_mail'] = ("mkaay@mkaay.de", "ranan@pyload.org", "spoob@pyload.org") + self.props = props + self.core = core + self.scripts = {} + + script_folders = ['scripts'+sep+'download_preparing'+sep, + 'scripts'+sep+'download_finished'+sep, + 'scripts'+sep+'package_finished'+sep, + 'scripts'+sep+'before_reconnect'+sep, + 'scripts'+sep+'after_reconnect'+sep] + self.core.check_file(script_folders, _("folders for scripts"), True) + + 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 + + def downloadStarts(self, pyfile): + 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 + + def downloadFinished(self, pyfile): + 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 + + def packageFinished(self, pypack): + """ + not implemented! + """ + pass + + def beforeReconnecting(self, ip): + 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 + + def afterReconnecting(self, ip): + for script in self.scripts['after_reconnect']: + try: + out = subprocess.Popen([join(self.folder, 'download_preparing', script), ip], stdout=subprocess.PIPE) + except: + pass diff --git a/pyLoadCore.py b/pyLoadCore.py index 203639c63..7aa38b9b1 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -119,10 +119,6 @@ class Core(object): self.check_file(self.config['general']['link_file'], _("file for links")) self.check_file(self.config['general']['failed_file'], _("file for failed links")) - - script_folders = ['scripts/download_preparing/', 'scripts/download_finished/', 'scripts/package_finished/', 'scripts/before_reconnect/', 'scripts/after_reconnect/'] # @TODO: yes, replace / with sep - self.check_file(script_folders, _("folders for scripts"), True) - if self.config['ssl']['activated']: self.check_install("OpenSSL", "OpenSSL for secure connection", True) self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True) -- cgit v1.2.3