From 4df2b77fdf42046fe19bd371be7c7255986b5980 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 6 Mar 2012 13:36:39 +0100 Subject: renamed hooks to addons, new filemanager and database, many new api methods you will loose ALL your LINKS, webinterface will NOT work --- module/threads/AddonThread.py | 65 +++++++++++++++++++++++++++++++++++++++ module/threads/DecrypterThread.py | 3 +- module/threads/DownloadThread.py | 12 ++++---- module/threads/HookThread.py | 65 --------------------------------------- module/threads/InfoThread.py | 6 ++-- module/threads/ThreadManager.py | 6 ++-- 6 files changed, 79 insertions(+), 78 deletions(-) create mode 100644 module/threads/AddonThread.py delete mode 100644 module/threads/HookThread.py (limited to 'module/threads') diff --git a/module/threads/AddonThread.py b/module/threads/AddonThread.py new file mode 100644 index 000000000..3a378ad6e --- /dev/null +++ b/module/threads/AddonThread.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from copy import copy +from traceback import print_exc + +from BaseThread import BaseThread + +class AddonThread(BaseThread): + """thread for addons""" + + def __init__(self, m, function, args, kwargs): + """Constructor""" + BaseThread.__init__(self, m) + + self.f = function + self.args = args + self.kwargs = kwargs + + self.active = [] + + m.localThreads.append(self) + + self.start() + + def getActiveFiles(self): + return self.active + + def addActive(self, pyfile): + """ Adds a pyfile to active list and thus will be displayed on overview""" + if pyfile not in self.active: + self.active.append(pyfile) + + def finishFile(self, pyfile): + if pyfile in self.active: + self.active.remove(pyfile) + + pyfile.finishIfDone() + + def run(self): + try: + try: + self.kwargs["thread"] = self + self.f(*self.args, **self.kwargs) + except TypeError, e: + #dirty method to filter out exceptions + if "unexpected keyword argument 'thread'" not in e.args[0]: + raise + + del self.kwargs["thread"] + self.f(*self.args, **self.kwargs) + except Exception, e: + if hasattr(self.f, "im_self"): + addon = self.f.im_self + addon.logError(_("An Error occured"), e) + if self.m.core.debug: + print_exc() + self.writeDebugReport(addon.__name__, plugin=addon) + + finally: + local = copy(self.active) + for x in local: + self.finishFile(x) + + self.m.localThreads.remove(self) \ No newline at end of file diff --git a/module/threads/DecrypterThread.py b/module/threads/DecrypterThread.py index ce3c8cd83..39448a620 100644 --- a/module/threads/DecrypterThread.py +++ b/module/threads/DecrypterThread.py @@ -55,6 +55,7 @@ class DecrypterThread(BaseThread): plugin.logDebug("Decrypted", plugin_result) result.extend(plugin_result) + #TODO result = uniqify(result) pack_names = {} urls = [] @@ -73,7 +74,7 @@ class DecrypterThread(BaseThread): self.m.core.api.addFiles(self.pid, urls) for p in pack_names.itervalues(): - self.m.core.api.addPackage(p.name, p.urls, p.dest, pack.password) + self.m.core.api.addPackage(p.name, p.urls, pack.password) if not result: self.log.info(_("No links decrypted")) diff --git a/module/threads/DownloadThread.py b/module/threads/DownloadThread.py index bd15b9b87..6239cddd8 100644 --- a/module/threads/DownloadThread.py +++ b/module/threads/DownloadThread.py @@ -64,11 +64,11 @@ class DownloadThread(BaseThread): self.log.info(_("Download starts: %s" % pyfile.name)) # start download - self.core.hookManager.downloadPreparing(pyfile) + self.core.addonManager.downloadPreparing(pyfile) pyfile.plugin.preprocessing(self) self.log.info(_("Download finished: %s") % pyfile.name) - self.core.hookManager.downloadFinished(pyfile) + self.core.addonManager.downloadFinished(pyfile) self.core.files.checkPackageFinished(pyfile) except NotImplementedError: @@ -117,7 +117,7 @@ class DownloadThread(BaseThread): self.log.warning(_("Download failed: %(name)s | %(msg)s") % {"name": pyfile.name, "msg": msg}) pyfile.error = msg - self.core.hookManager.downloadFailed(pyfile) + self.core.addonManager.downloadFailed(pyfile) self.clean(pyfile) continue @@ -158,7 +158,7 @@ class DownloadThread(BaseThread): print_exc() self.writeDebugReport(pyfile.plugin.__name__, pyfile) - self.core.hookManager.downloadFailed(pyfile) + self.core.addonManager.downloadFailed(pyfile) self.clean(pyfile) continue @@ -179,7 +179,7 @@ class DownloadThread(BaseThread): continue - except (Exception, BadHeader), e: + except Exception, e: if isinstance(e, BadHeader) and e.code == 500: pyfile.setStatus("temp. offline") self.log.warning(_("Download is temporary offline: %s") % pyfile.name) @@ -194,7 +194,7 @@ class DownloadThread(BaseThread): print_exc() self.writeDebugReport(pyfile.plugin.__name__, pyfile) - self.core.hookManager.downloadFailed(pyfile) + self.core.addonManager.downloadFailed(pyfile) self.clean(pyfile) continue diff --git a/module/threads/HookThread.py b/module/threads/HookThread.py deleted file mode 100644 index bffa72ca0..000000000 --- a/module/threads/HookThread.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from copy import copy -from traceback import print_exc - -from BaseThread import BaseThread - -class HookThread(BaseThread): - """thread for hooks""" - - def __init__(self, m, function, args, kwargs): - """Constructor""" - BaseThread.__init__(self, m) - - self.f = function - self.args = args - self.kwargs = kwargs - - self.active = [] - - m.localThreads.append(self) - - self.start() - - def getActiveFiles(self): - return self.active - - def addActive(self, pyfile): - """ Adds a pyfile to active list and thus will be displayed on overview""" - if pyfile not in self.active: - self.active.append(pyfile) - - def finishFile(self, pyfile): - if pyfile in self.active: - self.active.remove(pyfile) - - pyfile.finishIfDone() - - def run(self): - try: - try: - self.kwargs["thread"] = self - self.f(*self.args, **self.kwargs) - except TypeError, e: - #dirty method to filter out exceptions - if "unexpected keyword argument 'thread'" not in e.args[0]: - raise - - del self.kwargs["thread"] - self.f(*self.args, **self.kwargs) - except Exception, e: - if hasattr(self.f, "im_self"): - hook = self.f.im_self - hook.logError(_("An Error occured"), e) - if self.m.core.debug: - print_exc() - self.writeDebugReport(hook.__name__, plugin=hook) - - finally: - local = copy(self.active) - for x in local: - self.finishFile(x) - - self.m.localThreads.remove(self) \ No newline at end of file diff --git a/module/threads/InfoThread.py b/module/threads/InfoThread.py index 7db85803a..a8a2c6e7e 100644 --- a/module/threads/InfoThread.py +++ b/module/threads/InfoThread.py @@ -4,7 +4,7 @@ from time import time from traceback import print_exc -from module.Api import OnlineStatus +from module.Api import LinkStatus from module.common.packagetools import parseNames from module.utils import has_method, accumulate @@ -100,7 +100,7 @@ class InfoThread(BaseThread): if len(self.cache) >= 20 or force: #used for package generating - tmp = [(name, (url, OnlineStatus(name, plugin, "unknown", status, int(size)))) + tmp = [(name, (url, LinkStatus(name, plugin, "unknown", status, int(size)))) for name, size, status, url in self.cache] data = parseNames(tmp) @@ -161,7 +161,7 @@ class InfoThread(BaseThread): # only decrypt files if has_method(klass, "decryptFile"): - urls = p.decrypt(urls) + urls = klass.decrypt(urls) data, crypter = self.m.core.pluginManager.parseUrls(urls) return data diff --git a/module/threads/ThreadManager.py b/module/threads/ThreadManager.py index f8b5c0aba..b3a1e8c6c 100644 --- a/module/threads/ThreadManager.py +++ b/module/threads/ThreadManager.py @@ -47,7 +47,7 @@ class ThreadManager: self.log = core.log self.threads = [] # thread list - self.localThreads = [] #hook+decrypter threads + self.localThreads = [] #addon+decrypter threads self.pause = True @@ -189,7 +189,7 @@ class ThreadManager: ip = self.getIP() - self.core.hookManager.beforeReconnecting(ip) + self.core.addonManager.beforeReconnecting(ip) self.log.debug("Old IP: %s" % ip) @@ -206,7 +206,7 @@ class ThreadManager: reconn.wait() sleep(1) ip = self.getIP() - self.core.hookManager.afterReconnecting(ip) + self.core.addonManager.afterReconnecting(ip) self.log.info(_("Reconnected, new IP: %s") % ip) -- cgit v1.2.3