Add cleanup to the MirrorManager for the AptPackages.
authorCameron Dale <camrdale@gmail.com>
Sun, 2 Mar 2008 20:40:17 +0000 (12:40 -0800)
committerCameron Dale <camrdale@gmail.com>
Sun, 2 Mar 2008 20:40:17 +0000 (12:40 -0800)
apt_dht/AptPackages.py
apt_dht/MirrorManager.py

index 48dd448..1cd517a 100644 (file)
@@ -162,7 +162,6 @@ class AptPackages:
         
     def __del__(self):
         self.cleanup()
-        self.packages.close()
         
     def addRelease(self, cache_path, file_path):
         """Dirty hack until python-apt supports apt-pkg/indexrecords.h
@@ -282,6 +281,8 @@ class AptPackages:
     def cleanup(self):
         """Cleanup and close any loaded caches."""
         self.unload()
+        if self.unload_later and self.unload_later.active():
+            self.unload_later.cancel()
         self.packages.close()
         
     def findHash(self, path):
index 738fdeb..6c417b5 100644 (file)
@@ -75,6 +75,13 @@ class MirrorManager:
         d.errback(MirrorError("Site Not Found"))
         return d
     
+    def cleanup(self):
+        for site in self.apt_caches.keys():
+            for baseDir in self.apt_caches[site].keys():
+                self.apt_caches[site][baseDir].cleanup()
+                del self.apt_caches[site][baseDir]
+            del self.apt_caches[site]
+    
 class TestMirrorManager(unittest.TestCase):
     """Unit tests for the mirror manager."""
     
@@ -180,5 +187,6 @@ class TestMirrorManager(unittest.TestCase):
         for p in self.pending_calls:
             if p.active():
                 p.cancel()
+        self.client.cleanup()
         self.client = None
         
\ No newline at end of file