summaryrefslogtreecommitdiffstats
path: root/module/PluginThread.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-10-13 15:25:32 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-10-13 15:25:32 +0200
commit43460c40d00819535dfeecfdb80f8a608f2190fd (patch)
tree351518d8db3e5ee12689af4e019d5c3fc90bd212 /module/PluginThread.py
parentpatches from #392 (diff)
downloadpyload-43460c40d00819535dfeecfdb80f8a608f2190fd.tar.xz
improvement for hook plugins, new internal plugin type
Diffstat (limited to 'module/PluginThread.py')
-rw-r--r--module/PluginThread.py53
1 files changed, 37 insertions, 16 deletions
diff --git a/module/PluginThread.py b/module/PluginThread.py
index 8d1516bde..d29d609c7 100644
--- a/module/PluginThread.py
+++ b/module/PluginThread.py
@@ -26,6 +26,7 @@ from time import sleep, time, strftime, gmtime
from traceback import print_exc, format_exc
from pprint import pformat
from sys import exc_info, exc_clear
+from copy import copy
from types import MethodType
from pycurl import error
@@ -185,6 +186,10 @@ class DownloadThread(PluginThread):
self.m.core.hookManager.downloadStarts(pyfile)
pyfile.plugin.preprocessing(self)
+ self.m.log.info(_("Download finished: %s") % pyfile.name)
+ self.m.core.hookManager.downloadFinished(pyfile)
+ self.m.core.files.checkPackageFinished(pyfile)
+
except NotImplementedError:
self.m.log.error(_("Plugin %s is missing a function.") % pyfile.pluginname)
pyfile.setStatus("failed")
@@ -312,13 +317,9 @@ class DownloadThread(PluginThread):
pyfile.checkIfProcessed()
exc_clear()
- self.m.log.info(_("Download finished: %s") % pyfile.name)
+
#pyfile.plugin.req.clean()
- self.m.core.hookManager.downloadFinished(pyfile)
-
- self.m.core.files.checkPackageFinished(pyfile)
-
self.active = False
pyfile.finishIfDone()
self.m.core.files.save()
@@ -337,7 +338,6 @@ class DownloadThread(PluginThread):
class DecrypterThread(PluginThread):
"""thread for decrypting"""
- #----------------------------------------------------------------------
def __init__(self, manager, pyfile):
"""constructor"""
PluginThread.__init__(self, manager)
@@ -349,7 +349,9 @@ class DecrypterThread(PluginThread):
self.start()
- #----------------------------------------------------------------------
+ def getActiveFiles(self):
+ return [self.active]
+
def run(self):
"""run method"""
@@ -422,26 +424,45 @@ class HookThread(PluginThread):
"""thread for hooks"""
#----------------------------------------------------------------------
- def __init__(self, m, function, pyfile):
+ def __init__(self, m, function, args, kwargs):
"""Constructor"""
PluginThread.__init__(self, m)
self.f = function
- self.active = pyfile
+ self.args = args
+ self.kwargs = kwargs
- m.localThreads.append(self)
+ self.active = []
- if isinstance(pyfile, PyFile):
- pyfile.setStatus("processing")
+ 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"""
+ self.active.append(pyfile)
+
+ def finishFile(self, pyfile):
+ if pyfile in self.active:
+ self.active.remove(pyfile)
+
+ pyfile.finishIfDone()
+
def run(self):
- self.f(self.active)
+ try:
+ try:
+ self.f(*self.args, thread=self, **self.kwargs)
+ except TypeError:
+ self.f(*self.args, **self.kwargs)
+ finally:
+ local = copy(self.active)
+ for x in local:
+ self.finishFile(x)
- self.m.localThreads.remove(self)
- if isinstance(self.active, PyFile):
- self.active.finishIfDone()
+ self.m.localThreads.remove(self)
class InfoThread(PluginThread):