diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-12-31 16:01:24 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-12-31 16:01:24 +0100 |
commit | d35c003cc53d4723d1dfe0d81eeb9bea78cee594 (patch) | |
tree | ff9d47a0cee6116836955e37bf4471c1f1d82bee /module/threads/HookThread.py | |
parent | some account fixes (diff) | |
download | pyload-d35c003cc53d4723d1dfe0d81eeb9bea78cee594.tar.xz |
new crypter plugin API, now decrypting possible for now.
Diffstat (limited to 'module/threads/HookThread.py')
-rw-r--r-- | module/threads/HookThread.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/module/threads/HookThread.py b/module/threads/HookThread.py new file mode 100644 index 000000000..fe4a2a651 --- /dev/null +++ b/module/threads/HookThread.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from copy import copy + +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) + finally: + local = copy(self.active) + for x in local: + self.finishFile(x) + + self.m.localThreads.remove(self)
\ No newline at end of file |