diff options
author | mkaay <mkaay@mkaay.de> | 2010-12-23 11:28:03 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2010-12-23 11:28:03 +0100 |
commit | a4ba4ba12aff34c967f958576db40806656c3de8 (patch) | |
tree | 57a26d6559279fa4ed9c28fadfa31f4d36a7eceb /module/network | |
parent | new download backend integrated so far, downloading works, but still big todo... (diff) | |
download | pyload-a4ba4ba12aff34c967f958576db40806656c3de8.tar.xz |
fixed eta and progress, ready for first test
Diffstat (limited to 'module/network')
-rw-r--r-- | module/network/FTPBase.py | 4 | ||||
-rw-r--r-- | module/network/HTTPChunk.py | 4 | ||||
-rw-r--r-- | module/network/HTTPDownload.py | 8 | ||||
-rw-r--r-- | module/network/XDCCBase.py | 4 | ||||
-rw-r--r-- | module/network/helper.py | 8 |
5 files changed, 25 insertions, 3 deletions
diff --git a/module/network/FTPBase.py b/module/network/FTPBase.py index 036da383a..ce4627d0c 100644 --- a/module/network/FTPBase.py +++ b/module/network/FTPBase.py @@ -128,6 +128,10 @@ class FTPDownload(): self.speed = self.speedCalcLen self.speedCalcTime = inttime() self.speedCalcLen = 0 + try: + self.deferred.progress("percent", 100-int((self.size - self.arrived)/float(self.size)*100)) + except: + pass size = len(data) self.speedCalcLen += size self.arrived += size diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py index f26e681b6..48ebc13f3 100644 --- a/module/network/HTTPChunk.py +++ b/module/network/HTTPChunk.py @@ -92,6 +92,10 @@ class HTTPChunk(HTTPBase): self.speed = self.speedCalcLen self.speedCalcTime = inttime() self.speedCalcLen = 0 + try: + self.deferred.progress("percent", 100-int((self.size - self.arrived)/float(self.size)*100)) + except: + pass size = len(data) self.arrived += size diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index e38e1ba1b..1baf0ccad 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -167,6 +167,9 @@ class HTTPDownload(object): def speed(self): return self.getSpeed() + def calcProgress(self, p): + self.deferred.progress("percent", 100-int((self.size - self.arrived)/float(self.size)*100)) + def _copyChunks(self): fo = open(self.filename, "wb") for i in range(self.info.getCount()): @@ -219,6 +222,7 @@ class HTTPDownload(object): self.chunks.append(chunk) d = chunk.download() dg.addDeferred(d) + d.addProgress("percent", self.calcProgress) if not self.info.loaded: size = chunk.size @@ -266,6 +270,7 @@ class HTTPDownload(object): break self.chunks.append(chunk) dg.addDeferred(d) + d.addProgress("percent", self.calcProgress) if not self.info.loaded: self.info.addChunk("%s.chunk%d" % (self.filename, i), chunk.range, chunk.getEncoding()) @@ -274,7 +279,8 @@ class HTTPDownload(object): dg.addCallback(self._copyChunks) if not len(self.chunks): dg.callback() - return WrappedHTTPDeferred(self, dg) + dg.addErrback(self.deferred.error) + return WrappedHTTPDeferred(self, self.deferred) else: raise Exception("no chunks") diff --git a/module/network/XDCCBase.py b/module/network/XDCCBase.py index 6d9978b80..d36d6e897 100644 --- a/module/network/XDCCBase.py +++ b/module/network/XDCCBase.py @@ -120,6 +120,10 @@ class XDCCDownload(): self.speed = self.speedCalcLen self.speedCalcTime = inttime() self.speedCalcLen = 0 + try: + self.deferred.progress("percent", 100-int((self.size - self.arrived)/float(self.size)*100)) + except: + pass size = len(data) self.speedCalcLen += size self.arrived += size diff --git a/module/network/helper.py b/module/network/helper.py index ed9a88798..ebe0fa8f5 100644 --- a/module/network/helper.py +++ b/module/network/helper.py @@ -36,7 +36,6 @@ class Deferred(): kwargs.update(ckwargs) callInThread(f, *args, **kwargs) - #test not in use def addProgress(self, chain, f): if self.prgr.has_key(chain): self.prgr[chain].append(f) @@ -67,7 +66,6 @@ class Deferred(): kwargs.update(ckwargs) callInThread(f, *args, **kwargs) - #test not in use def progress(self, chain, *args, **kwargs): if not self.prgr.has_key(chain): return @@ -141,12 +139,18 @@ class WrappedDeferred(object): def addErrback(self, *args, **kwargs): self.__dict__["d"].addErrback(*args, **kwargs) + def addProgress(self, *args, **kwargs): + self.__dict__["d"].addProgress(*args, **kwargs) + def callback(self, *args, **kwargs): self.__dict__["d"].callback(*args, **kwargs) def error(self, *args, **kwargs): self.__dict__["d"].error(*args, **kwargs) + def progress(self, *args, **kwargs): + self.__dict__["d"].progress(*args, **kwargs) + def __getattr__(self, attr): return getattr(self.download, attr) |