diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2005-06-03 07:58:33 +0000 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2005-06-03 07:58:33 +0000 |
| commit | 9103e321939804418a861cdaf25f8df1347d768b (patch) | |
| tree | 8638d7c834bbc1ad57adcd25fbc48c3fcca5aa71 | |
| parent | d2a55a7ccf141cd9706f62f87c74d10551f6a799 (diff) | |
| download | python-apt-9103e321939804418a861cdaf25f8df1347d768b.tar.gz | |
* added reapplyFilter, added a CacheChanged() method that is used by the clients (e.s. the Packages class) when they install/remove etc something
| -rw-r--r-- | apt/cache.py | 37 | ||||
| -rw-r--r-- | apt/package.py | 15 |
2 files changed, 43 insertions, 9 deletions
diff --git a/apt/cache.py b/apt/cache.py index 1988e26b..465a210a 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -1,5 +1,6 @@ import apt_pkg from apt import Package +from apt.progress import OpTextProgress from UserDict import UserDict class Cache(object): @@ -13,11 +14,22 @@ class Cache(object): self._dict = {} # build the packages dict + if progress != None: + progress.Op = "Building data structures" + i=last=0 + size=len(self._cache.Packages) for pkg in self._cache.Packages: + if progress != None and last+100 < i: + progress.Update(i/float(size)*100) + last=i # drop stuff with no versions (cruft) if len(pkg.VersionList) > 0: - self._dict[pkg.Name] = Package(self._cache, self._depcache, self._records, pkg) - + self._dict[pkg.Name] = Package(self._cache, self._depcache, + self._records, self, pkg) + i += 1 + if progress != None: + progress.Done() + def __getitem__(self, key): return self._dict[key] @@ -49,6 +61,9 @@ class Cache(object): def Commit(self, fprogress, iprogress): self._depcache.Commit(fprogress, iprogress) + def CacheChange(self): + " called internally if the cache changes, emit a signal then " + pass # ----------------------------- experimental interface class Filter(object): @@ -66,6 +81,7 @@ class FilteredCache(Cache): def __init__(self, progress=None): Cache.__init__(self, progress) self._filtered = {} + self._filters = [] def __len__(self): return len(self._filtered) @@ -81,11 +97,22 @@ class FilteredCache(Cache): except KeyError: return False return True + + def reapplyFilter(self): + for pkg in self._dict.keys(): + for f in self._filters: + if f.apply(self._dict[pkg]): + self._filtered[pkg] = 1 + def AddFilter(self, filter): - for pkg in self._dict.keys(): - if filter.apply(self._dict[pkg]): - self._filtered[pkg] = 1 + self._filters.append(filter) + self.reapplyFilter() + + def CacheChange(self): + " called internally if the cache changes, emit a signal then " + reapplyFilter() + if __name__ == "__main__": print "Cache self test" diff --git a/apt/package.py b/apt/package.py index 014b720f..8f1d00a0 100644 --- a/apt/package.py +++ b/apt/package.py @@ -2,12 +2,13 @@ import apt_pkg, string class Package(object): - def __init__(self, cache, depcache, records, pkgiter): + def __init__(self, cache, depcache, records, pcache, pkgiter): """ Init the Package object """ - self._cache = cache + self._cache = cache # low level cache self._depcache = depcache self._records = records self._pkg = pkgiter + self._pcache = pcache # python cache in cache.py pass # helper @@ -18,6 +19,9 @@ class Package(object): ver = self._depcache.GetCandidateVer(self._pkg) else: ver = self._pkg.CurrentVer + if ver.FileList == None: + print "got: %s " % ver.FileList + return file, index = ver.FileList.pop(0) self._records.Lookup((file,index)) @@ -112,11 +116,14 @@ class Package(object): # depcache action def MarkKeep(self): - return self._depcache.MarkKeep(self._pkg) + self._depcache.MarkKeep(self._pkg) + self._pcache.CacheChange() def MarkDelete(self): - return self._depcache.MarkDelete(self._pkg) + self._depcache.MarkDelete(self._pkg) + self._pcache.CacheChange() def MarkInstall(self): return self._depcache.MarkInstall(self._pkg) + self._pcache.CacheChange() # size def PackageSize(self, UseCandidate=True): |
