r227 - branches/rewrite/src
Otavio Salvador
partial-mirror-devel@lists.alioth.debian.org
Tue, 21 Sep 2004 13:13:59 -0600
Author: otavio
Date: Tue Sep 21 13:13:58 2004
New Revision: 227
Modified:
branches/rewrite/src/Download.py
Log:
Add DownloadQueue class and use it on code. This will have lock support and make more easy to add thread support.
Modified: branches/rewrite/src/Download.py
==============================================================================
--- branches/rewrite/src/Download.py (original)
+++ branches/rewrite/src/Download.py Tue Sep 21 13:13:58 2004
@@ -16,11 +16,27 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# $Id$
-import pycurl, sys, string
+import pycurl
+import sys, string
+
+from Queue import Queue
import signal
from signal import SIGPIPE, SIG_IGN
+class DownloadQueue(Queue):
+ """ Implemente a Queue without duplicated items. """
+ def __init__(self, maxsize=0):
+ Queue.__init__(self, maxsize)
+
+ def put(self, item, block=True, timeout=None):
+ if item not in self.queue:
+ Queue.put(self, item, block, timeout)
+
+ def put_nowait(self, item):
+ if item not in self.queue:
+ Queue.put_nowait(self, item)
+
def progress(download_t, download_d, upload_t, upload_d):
print "Total to download", download_t
print "Total downloaded", download_d
@@ -29,15 +45,14 @@
class Download:
""" Download queue """
- queue = []
+ queue = DownloadQueue()
""" Fetcher to use """
fetcher = None
def __init__(self, uri, destine):
- if (uri, destine) not in self.queue:
- self.queue.append((uri, destine))
+ self.queue.put((uri, destine))
- print len(self.queue)
+ print self.queue.qsize()
if not self.fetcher:
self.fetcher = DownloadFetcher(2)
@@ -71,7 +86,7 @@
num_processed = 0
while 1:
while Download.queue and free:
- url, filename = Download.queue.pop(0)
+ url, filename = Download.queue.get()
c = free.pop()
c.fp = open(filename, "wb")
c.setopt(pycurl.URL, url)