19
19
"""This module is supposed to make sure that plugins:
20
20
-don't crash the program
21
-errorCallback would be called if anything bad happen
21
-errorCallback is called if anything bad happen
22
22
-plugins are running in their own threads
24
-number of concurrent uploads is not exceeded
24
26
Do note that this module is not a security sandbox
25
27
(fe: malicious plugin stil can delete home folder)"""
27
29
from threading import Thread
28
30
from sys import exc_info
31
from plugins.libs.cliHelper import printLink, printProgressToCLI
32
from Settings import Settings
30
35
from helpers.gnomeHelper import getPyShareHomeDirectory
31
36
LOG_PATH = getPyShareHomeDirectory() + 'errorLog'
53
def uploadFiles(uploader, errorCallback,
59
def uploadFiles(Uploader, errorCallback,
54
60
files, resultCallbackFunction, progressCallbackFunction, fileNumber, semaphore, username="", password=""):
55
61
"""uploads files with given uploader, each file in new thread
56
62
each thread would be given incremented fileNumber
58
64
errorCallback function will be called if Exception occurs"""
61
t = runMethodInThread(uploader.uploadFile,
62
(file, resultCallbackFunction, progressCallbackFunction, fileNumber, semaphore, username, password),
67
t = runMethodInThread(__createUploaderInstanceAndUploadFile,
68
(Uploader, file, resultCallbackFunction, progressCallbackFunction, fileNumber, semaphore, username, password),
65
71
threadList.append(t)
69
def uploadFile(uploader, errorCallback,
75
def uploadFile(Uploader, errorCallback,
70
76
file, resultCallbackFunction, progressCallbackFunction, fileNumber, semaphore, username="", password=""):
71
77
"""uploads file with given uploader
72
78
errorCallback function will be called if Exception occurs"""
73
t = runMethodInThread(uploader.uploadFile,
74
(file, resultCallbackFunction, progressCallbackFunction, fileNumber, semaphore, username, password),
79
t = runMethodInThread(__createUploaderInstanceAndUploadFile,
80
(Uploader, file, semaphore,
82
resultCallbackFunction, progressCallbackFunction,
88
def __createUploaderInstanceAndUploadFile(Uploader, file, semaphore,
90
resultCallbackFunction=printLink, progressCallbackFunction=printProgressToCLI,
92
uploader = Uploader(fileNumber, progressCallbackFunction)
93
credentials = Settings().getUploaderCredentials(uploader.NAME)
95
username, password = credentials
98
uploader.upload(file, resultCallbackFunction, username, password)