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 /apt/cache.py | |
| 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
Diffstat (limited to 'apt/cache.py')
| -rw-r--r-- | apt/cache.py | 37 |
1 files changed, 32 insertions, 5 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" |
