aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Tools
diff options
context:
space:
mode:
authorFraxinas <andreas.frisch@multimedia-labs.de>2009-05-11 22:05:13 +0200
committerFraxinas <andreas.frisch@multimedia-labs.de>2009-05-11 22:05:13 +0200
commitb4f81157894ee05e23eafa5ff6accbdc280d9cc6 (patch)
tree0117927c86b650959063bcb183bd286b9a272c92 /lib/python/Tools
parent019762d6cd083eb6d49f3611eb692aad2f9dd506 (diff)
downloadenigma2-b4f81157894ee05e23eafa5ff6accbdc280d9cc6.tar.gz
enigma2-b4f81157894ee05e23eafa5ff6accbdc280d9cc6.zip
move http progress downloader class into own tool py
Diffstat (limited to 'lib/python/Tools')
-rw-r--r--lib/python/Tools/Downloader.py53
-rw-r--r--lib/python/Tools/Makefile.am3
2 files changed, 55 insertions, 1 deletions
diff --git a/lib/python/Tools/Downloader.py b/lib/python/Tools/Downloader.py
new file mode 100644
index 00000000..ffc24c1c
--- /dev/null
+++ b/lib/python/Tools/Downloader.py
@@ -0,0 +1,53 @@
+from twisted.web import client
+from twisted.internet import reactor, defer
+from twisted.python import failure
+
+class HTTPProgressDownloader(client.HTTPDownloader):
+ def __init__(self, url, outfile, headers=None):
+ client.HTTPDownloader.__init__(self, url, outfile, headers=headers, agent="Dreambox HTTP Downloader")
+ self.status = None
+ self.progress_callback = None
+ self.deferred = defer.Deferred()
+
+ def noPage(self, reason):
+ if self.status == "304":
+ print reason.getErrorMessage()
+ client.HTTPDownloader.page(self, "")
+ else:
+ client.HTTPDownloader.noPage(self, reason)
+
+ def gotHeaders(self, headers):
+ if self.status == "200":
+ if headers.has_key("content-length"):
+ self.totalbytes = int(headers["content-length"][0])
+ else:
+ self.totalbytes = 0
+ self.currentbytes = 0.0
+ return client.HTTPDownloader.gotHeaders(self, headers)
+
+ def pagePart(self, packet):
+ if self.status == "200":
+ self.currentbytes += len(packet)
+ if self.totalbytes and self.progress_callback:
+ self.progress_callback(self.currentbytes, self.totalbytes)
+ return client.HTTPDownloader.pagePart(self, packet)
+
+ def pageEnd(self):
+ return client.HTTPDownloader.pageEnd(self)
+
+class downloadWithProgress:
+ def __init__(self, url, outputfile, contextFactory=None, *args, **kwargs):
+ scheme, host, port, path = client._parse(url)
+ self.factory = HTTPProgressDownloader(url, outputfile, *args, **kwargs)
+ self.connection = reactor.connectTCP(host, port, self.factory)
+
+ def start(self):
+ return self.factory.deferred
+
+ def stop(self):
+ print "[stop]"
+ self.connection.disconnect()
+
+ def addProgress(self, progress_callback):
+ print "[addProgress]"
+ self.factory.progress_callback = progress_callback
diff --git a/lib/python/Tools/Makefile.am b/lib/python/Tools/Makefile.am
index fd23bd12..e7904d66 100644
--- a/lib/python/Tools/Makefile.am
+++ b/lib/python/Tools/Makefile.am
@@ -4,4 +4,5 @@ install_PYTHON = \
FuzzyDate.py XMLTools.py Directories.py NumericalTextInput.py \
KeyBindings.py BoundFunction.py ISO639.py Notifications.py __init__.py \
RedirectOutput.py DreamboxHardware.py Import.py Event.py CList.py \
- LoadPixmap.py Profile.py HardwareInfo.py Transponder.py ASCIItranslit.py
+ LoadPixmap.py Profile.py HardwareInfo.py Transponder.py ASCIItranslit.py \
+ Downloader.py