diff options
-rw-r--r-- | module/HookManager.py | 71 | ||||
-rw-r--r-- | module/file_list.py | 2 | ||||
-rw-r--r-- | module/thread_list.py | 4 | ||||
-rwxr-xr-x | pyLoadCore.py | 8 | ||||
-rw-r--r-- | scripts/Readme.txt | 25 |
5 files changed, 94 insertions, 16 deletions
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() diff --git a/module/file_list.py b/module/file_list.py index 1c4c4776b..7c68a7427 100644 --- a/module/file_list.py +++ b/module/file_list.py @@ -149,7 +149,7 @@ class File_List(object): info["active"] = pyfile.active info["plugin"] = pyfile.plugin.props['name'] return info - + def continueAborted(self): [[self.packager.resetFileStatus(x.id) for x in p.files if x.status.type == "aborted"] for p in self.data["queue"]] diff --git a/module/thread_list.py b/module/thread_list.py index 9211c7c2e..1a66bf6f5 100644 --- a/module/thread_list.py +++ b/module/thread_list.py @@ -200,7 +200,7 @@ class Thread_List(object): def reconnect(self): self.parent.logger.info("Start reconnect") ip = re.match(".*Current IP Address: (.*)</body>.*", urllib2.urlopen("http://checkip.dyndns.org/").read()).group(1) - #self.parent.hookManager.beforeReconnecting(ip) + self.parent.hookManager.beforeReconnecting(ip) reconn = subprocess.Popen(self.parent.config['reconnect']['method'])#, stdout=subprocess.PIPE) reconn.wait() time.sleep(1) @@ -211,7 +211,7 @@ class Thread_List(object): except: ip = "" time.sleep(1) - #self.parent.hookManager.afterReconnecting(ip) + self.parent.hookManager.afterReconnecting(ip) self.parent.logger.info("Reconnected, new IP: " + ip) def stopAllDownloads(self): diff --git a/pyLoadCore.py b/pyLoadCore.py index 9a9c0d6ff..7aa38b9b1 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -104,7 +104,7 @@ class Core(object): self.do_kill = False
self.do_restart = False
- translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']])
+ translation = gettext.translation("pyLoad", join(self.path, "locale"), languages=[self.config['general']['language']])
translation.install(unicode=True)
self.check_install("Crypto", "pycrypto to decode container files")
@@ -347,10 +347,10 @@ class Core(object): self.last_update_check = time.time()
def install_update(self):
- if self.config['updates']['search_updates']: + if self.config['updates']['search_updates']:
if self.core.config['updates']['install_updates']:
- version_check = Request().load("http://get.pyload.org/get/update/%s/" % (CURRENT_VERSION, )) - else: + version_check = Request().load("http://get.pyload.org/get/update/%s/" % (CURRENT_VERSION, ))
+ else:
version_check = Request().load("http://get.pyload.org/check/%s/" % (CURRENT_VERSION, ))
if version_check == "":
return False
diff --git a/scripts/Readme.txt b/scripts/Readme.txt new file mode 100644 index 000000000..1c326801d --- /dev/null +++ b/scripts/Readme.txt @@ -0,0 +1,25 @@ + ############################# + ### pyLoad Script Support ### + ############################# + +pyLoad is able to start any kind of scripts at given events. +Simply put your script in a suitable folder and pyLoad will execute it at the given events and pass some arguments to them. + +--> Note: Scripts, which starts with # will be ignored! +For Example: #converter.sh will not be executed. + +--> Note: You have to restart pyload when you change script names or locations. + +Below you see the list of arguments, which are passed to the scripts. + +## Argument list ## + +download_preparing: pluginname url + +download_finished: pluginname url filename filelocation + +package_finshed: packagename packagelocation + +before_reconnect: oldip + +after_reconnect: newip
\ No newline at end of file |