r379 - in branches/rewrite: . src

Otavio Salvador partial-mirror-devel@lists.alioth.debian.org
Sun, 28 Nov 2004 14:56:21 -0700


Author: otavio
Date: Sun Nov 28 14:56:20 2004
New Revision: 379

Modified:
   branches/rewrite/   (props changed)
   branches/rewrite/src/Download.py
   branches/rewrite/src/FileSystem.py
Log:
Simplefied FileSystem uncompress code; Change Download to write all
pending data to files, closing al curl hanldes after finish download.


Modified: branches/rewrite/src/Download.py
==============================================================================
--- branches/rewrite/src/Download.py	(original)
+++ branches/rewrite/src/Download.py	Sun Nov 28 14:56:20 2004
@@ -63,7 +63,6 @@
         self._curl.perform()
 
     def close(self):
-        self.http_code = self._curl.getinfo(pycurl.HTTP_CODE)
         self._fp.close()
         self._fp = None
         self._curl.close()
@@ -125,12 +124,16 @@
             self._multi.select()
             while 1:
                 ret, num_handles = self._multi.perform()
-                print ret, num_handles
                 # If we doesn't have data pending, process the others.
                 if ret != pycurl.E_CALL_MULTI_PERFORM:
                     # If we already tranfered all files, stop.
                     if num_handles == 0:
                         self._running = False
+                        while len(self._multi.handles) > 0:
+                            c = self._multi.handles.pop()
+                            c.close()
+                            del c
+                        self._running = False
                         return
                     else:
                         break

Modified: branches/rewrite/src/FileSystem.py
==============================================================================
--- branches/rewrite/src/FileSystem.py	(original)
+++ branches/rewrite/src/FileSystem.py	Sun Nov 28 14:56:20 2004
@@ -91,26 +91,20 @@
         """Uncompress a file"""
         print 'Uncompressing', f
         # uncompress the file
-        compressedFile = gzip.GzipFile(f, 'rb')
+        compressedFile = gzip.GzipFile(f)
         try:
             outputFile = open(f.split('.gz')[0], "wb")
         except IOError, msg:
             print msg
             sys.exit(1)
 
-        numBytes = 0
-        while True:
-            try:
-                data = compressedFile.read(64 * 1024)
-            except IOError, msg:
-                print "Corrupted file %s. Fatal error!" % f
-                sys.exit(1)
-                
-            if not data:
-                break
-            outputFile.write(data)
-            numBytes = numBytes + len(data)
+        try:
+            data = compressedFile.read()
+        except IOError, msg:
+            print "Error while reading file %s (%s). Fatal error!" % (f, msg)
+            sys.exit(1)
 
+        outputFile.write(data)
         compressedFile.close()
         outputFile.close()
         return True