r234 - branches/rewrite/src

Otavio Salvador partial-mirror-devel@lists.alioth.debian.org
Tue, 21 Sep 2004 18:20:33 -0600


Author: otavio
Date: Tue Sep 21 18:20:32 2004
New Revision: 234

Modified:
   branches/rewrite/src/Download.py
Log:
More information about current download.

Modified: branches/rewrite/src/Download.py
==============================================================================
--- branches/rewrite/src/Download.py	(original)
+++ branches/rewrite/src/Download.py	Tue Sep 21 18:20:32 2004
@@ -31,28 +31,23 @@
         if item not in self.queue:
             self.queue.append(item)
 
-def progress(download_t, download_d, upload_t, upload_d):
-    print "Total to download", download_t
-    print "Total downloaded", download_d
-    print "Total to upload", upload_t
-    print "Total uploaded", upload_d
-
 class DownloadThread(threading.Thread):
     def run(self):
         while 1:
             url, filename = Download.queue.get()
             f = open(filename, "wb")
             curl = pycurl.Curl()
-            curl.setopt(pycurl.HTTPHEADER, ["User-Agent: PycURL"])
             curl.setopt(pycurl.FOLLOWLOCATION, 1)
             curl.setopt(pycurl.MAXREDIRS, 5)
             curl.setopt(pycurl.URL, url)
             curl.setopt(pycurl.WRITEDATA, f)
             curl.setopt(pycurl.NOSIGNAL, 1)
             curl.setopt(pycurl.CONNECTTIMEOUT, 30)
-            curl.setopt(pycurl.PROGRESSFUNCTION, progress)
+            curl.setopt(pycurl.PROGRESSFUNCTION, self.progress)
             curl.setopt(pycurl.NOPROGRESS, 0)
             curl.setopt(pycurl.TIMEOUT, 300)
+
+            self.url = url
             
             try:
                 curl.perform()
@@ -65,6 +60,14 @@
             sys.stdout.write(".")
             sys.stdout.flush()
 
+    def progress(self, download_t, download_d, upload_t, upload_d):
+        self.download_total = download_t
+        self.download_current = download_d
+        if not download_t:
+            return
+        
+        print "[ %.2f%% %s ]" % ((download_d/download_t)*100, self.url)
+
 class Download:
     """ Download queue """
     queue = DownloadQueue()
@@ -81,9 +84,6 @@
                 self.fetchers.append(t)
                 t.start()
 
-        # Information ... should be removed
-        print str(self.queue.qsize()) + " / " + str(len(self.fetchers))
-
 urls = open(sys.argv[1]).readlines()
 fileno = 1
 for url in urls: