]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_p2p/MirrorManager.py
Final abstract for submission.
[quix0rs-apt-p2p.git] / apt_p2p / MirrorManager.py
index 4c19f1070afb66e49d53250251342dad2a845e11..f91db7647459d05ec40c8a4c066bfb943e382080 100644 (file)
@@ -25,15 +25,12 @@ class MirrorManager:
     
     @type cache_dir: L{twisted.python.filepath.FilePath}
     @ivar cache_dir: the directory to use for storing all files
-    @type unload_delay: C{int}
-    @ivar unload_delay: the time to wait before unloading the apt cache
     @type apt_caches: C{dictionary}
     @ivar apt_caches: the avaliable mirrors
     """
     
-    def __init__(self, cache_dir, unload_delay):
+    def __init__(self, cache_dir):
         self.cache_dir = cache_dir
-        self.unload_delay = unload_delay
         self.apt_caches = {}
     
     def extractPath(self, url):
@@ -93,7 +90,7 @@ class MirrorManager:
         if baseDir not in self.apt_caches[site]:
             site_cache = self.cache_dir.child(aptpkg_dir).child('mirrors').child(site + baseDir.replace('/', '_'))
             site_cache.makedirs
-            self.apt_caches[site][baseDir] = AptPackages(site_cache, self.unload_delay)
+            self.apt_caches[site][baseDir] = AptPackages(site_cache)
     
     def updatedFile(self, url, file_path):
         """A file in the mirror has changed or been added.
@@ -112,11 +109,10 @@ class MirrorManager:
         @return: a deferred that will fire with the returned L{Hash.HashObject}
         """
         site, baseDir, path = self.extractPath(url)
+        self.init(site, baseDir)
         if site in self.apt_caches and baseDir in self.apt_caches[site]:
             return self.apt_caches[site][baseDir].findHash(path)
-        d = defer.Deferred()
-        d.errback(MirrorError("Site Not Found"))
-        return d
+        return defer.fail(MirrorError("Site Not Found"))
     
     def cleanup(self):
         for site in self.apt_caches.keys():
@@ -133,7 +129,7 @@ class TestMirrorManager(unittest.TestCase):
     client = None
     
     def setUp(self):
-        self.client = MirrorManager(FilePath('/tmp/.apt-p2p'), 300)
+        self.client = MirrorManager(FilePath('/tmp/.apt-p2p'))
         
     def test_extractPath(self):
         """Test extracting the site and base directory from various mirrors."""