diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2014-01-12 11:50:24 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2014-01-12 11:50:24 +0100 |
commit | b8670f44e228d6fd01b42c3a950756b6f56e1701 (patch) | |
tree | d4f6fb9a97528dbeac5272d00f84fa5e41bc9ed9 | |
parent | small cleanup, fixed some test cases (diff) | |
download | pyload-b8670f44e228d6fd01b42c3a950756b6f56e1701.tar.xz |
new manager to schedule downloads
-rw-r--r-- | pyload/DownloadManager.py | 44 | ||||
-rw-r--r-- | pyload/api/DownloadApi.py | 4 | ||||
-rw-r--r-- | pyload/threads/ThreadManager.py | 3 |
3 files changed, 46 insertions, 5 deletions
diff --git a/pyload/DownloadManager.py b/pyload/DownloadManager.py index b877db355..706f9afeb 100644 --- a/pyload/DownloadManager.py +++ b/pyload/DownloadManager.py @@ -16,6 +16,12 @@ # @author: RaNaN ############################################################################### +from threading import Event +from ReadWriteLock import ReadWriteLock + +from utils import lock, read_lock, primary_uid +from threads.DownloadThread import DownloadThread +from threads.DecrypterThread import DecrypterThread class DownloadManager: """ Schedules and manages download and decrypter jobs. """ @@ -23,6 +29,42 @@ class DownloadManager: def __init__(self, core): self.core = core + #: won't start download when true + self.paused = True + + #: each thread is in exactly one category + self.free = [] + #: a thread that in working must have a pyfile as active attribute + self.working = [] + + #: indicates when reconnect has occured + self.reconnecting = Event() + self.reconnecting.clear() + + self.lock = ReadWriteLock() + + @lock + def done(self, thread): + """ Switch thread from working to free state """ + self.working.remove(thread) + self.free.append(thread) + + @read_lock + def activeDownloads(self, user): + """ retrieve pyfiles of running downloads """ + uid = primary_uid(user) + return [x.active for x in self.working if uid is None or x.active.owner == uid] + + def getProgressList(self, user): + """ Progress of all running downloads """ + return [p.getProgressInfo() for p in self.activeDownloads(user)] + + def canDownload(self, user): + """ check if a user is eligible to start a new download """ + + def abort(self): + """ Cancels all downloads """ + def work(self): - """ Does the periodical work """ + """ main routine that does the periodical work """ diff --git a/pyload/api/DownloadApi.py b/pyload/api/DownloadApi.py index 526fff6e0..dbb289db1 100644 --- a/pyload/api/DownloadApi.py +++ b/pyload/api/DownloadApi.py @@ -32,7 +32,7 @@ class DownloadApi(ApiComponent): folder = folder.replace("http://", "").replace(":", "").replace("\\", "_").replace("..", "") self.core.log.info(_("Added package %(name)s as folder %(folder)s") % {"name": name, "folder": folder}) - pid = self.core.files.addPackage(name, folder, root, password, site, comment, paused) + pid = self.core.files.addPackage(name, folder, root, password, site, comment, paused, self.primaryUID) return pid @@ -76,7 +76,7 @@ class DownloadApi(ApiComponent): """ hoster, crypter = self.core.pluginManager.parseUrls(links) - self.core.files.addLinks(hoster + crypter, pid) + self.core.files.addLinks(hoster + crypter, pid, self.primaryUID) if hoster: self.core.threadManager.createInfoThread(hoster, pid) diff --git a/pyload/threads/ThreadManager.py b/pyload/threads/ThreadManager.py index 62664a590..298b0402d 100644 --- a/pyload/threads/ThreadManager.py +++ b/pyload/threads/ThreadManager.py @@ -36,8 +36,7 @@ from InfoThread import InfoThread class ThreadManager: - """manages the download threads, assign jobs, reconnect etc""" - + """manages all non download related threads and jobs """ def __init__(self, core): """Constructor""" |