forked from pyload/pyload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddon.py
More file actions
66 lines (46 loc) · 1.47 KB
/
Copy pathAddon.py
File metadata and controls
66 lines (46 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
# @author: RaNaN
import Queue
import copy
import os
import sys
import time
import traceback
from pyload.Thread.Plugin import PluginThread
class AddonThread(PluginThread):
"""thread for addons"""
def __init__(self, m, function, args, kwargs):
"""Constructor"""
PluginThread.__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.copy(self.active)
for x in local:
self.finishFile(x)
self.m.localThreads.remove(self)