r335 - in branches/rewrite: . src
Otavio Salvador
partial-mirror-devel@lists.alioth.debian.org
Wed, 17 Nov 2004 07:21:14 -0700
Author: otavio
Date: Wed Nov 17 07:21:13 2004
New Revision: 335
Modified:
branches/rewrite/ (props changed)
branches/rewrite/src/Download.py
Log:
r306@nurf: otavio | 2004-11-17T14:20:25.873621Z
Add resume and support to skip when we already have the full file.
Modified: branches/rewrite/src/Download.py
==============================================================================
--- branches/rewrite/src/Download.py (original)
+++ branches/rewrite/src/Download.py Wed Nov 17 07:21:13 2004
@@ -20,6 +20,7 @@
import threading
from Queue import Queue, Empty
+from os.path import getsize, exists
from DisplayStatus import *
class DownloadQueue(Queue):
@@ -46,6 +47,7 @@
threading.Thread.__init__(self)
def run(self):
+
while 1:
try:
url, filename = Download.queue.get_nowait()
@@ -53,12 +55,13 @@
# Doesn't have any other file to download so exit.
return
- f = open(filename, "wb")
curl = pycurl.Curl()
+ if exists(filename):
+ curl.setopt(pycurl.CURLOPT_RESUME_FROM, getsize(filename))
+
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.URL, url)
- curl.setopt(pycurl.WRITEFUNCTION, f.write)
curl.setopt(pycurl.NOSIGNAL, 1)
curl.setopt(pycurl.CONNECTTIMEOUT, 30)
curl.setopt(pycurl.PROGRESSFUNCTION, self.progress)
@@ -66,6 +69,9 @@
curl.setopt(pycurl.TIMEOUT, 300)
curl.setopt(pycurl.FAILONERROR, 1)
+ f = open(filename, "ab")
+ curl.setopt(pycurl.WRITEFUNCTION, f.write)
+
self.url = url
# Store counter information about it
@@ -77,7 +83,9 @@
try:
curl.perform()
except Exception, e:
- self.DisplayStatus.errored(url, e)
+ # 416 is returned when we already have full file
+ if e[1].split()[-1] != '416':
+ self.DisplayStatus.errored(url, e)
curl.close()
try: