diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2005-05-11 14:13:16 +0000 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2005-05-11 14:13:16 +0000 |
| commit | e78e4b71fc600cf251eead62cec6a7c07165e38b (patch) | |
| tree | 483321a0752831370358ad47963c4fbff0034622 /apt/cache.py | |
| parent | f637fdcce22f31ed51a12b860ada598286180bdb (diff) | |
| download | python-apt-e78e4b71fc600cf251eead62cec6a7c07165e38b.tar.gz | |
* __init__ added for the apt module, IsInstalled() added
Diffstat (limited to 'apt/cache.py')
| -rw-r--r-- | apt/cache.py | 69 |
1 files changed, 52 insertions, 17 deletions
diff --git a/apt/cache.py b/apt/cache.py index 2dac0739..1693498d 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -2,21 +2,15 @@ import apt_pkg from apt import Package from UserDict import UserDict -class Filter(object): - def apply(self, pkg): - pass - - - class Cache(object): - def __init__(self): - self.open() + def __init__(self, progress=None): + self.open(progress) - def open(self): - self._cache = apt_pkg.GetCache() + def open(self, progress): + self._cache = apt_pkg.GetCache(progress) self._depcache = apt_pkg.GetDepCache(self._cache) self._records = apt_pkg.GetPkgRecords(self._cache) - self._depcache.Init() + self._depcache.Init(progress) self._dict = {} # build the packages dict @@ -47,15 +41,56 @@ class Cache(object): def Commit(self, fprogress, iprogress): self._depcache.Commit(fprogress, iprogress) + + +class Filter(object): + def apply(self, pkg): + return True + +class MarkedChangesFilter(Filter): + def apply(self, pkg): + if pkg.MarkedInstall() or pkg.MarkedDelete() or pkg.MarkedUpgrade(): + return True + else: + return False + +class FilteredCache(Cache): + def __len__(self): + return len(self._filtered) + + def __getitem__(self, key): + return self._dict[key] + + def keys(self): + return self._filtered.keys() + + def has_key(self, key): + try: + self._filtered[key] + except KeyError: + return False + return True + def AddFilter(self, filter): + for pkg in self._dict.keys(): + if filter.apply(self._dict[pkg]): + self._filtered[pkg] = 1 + if __name__ == "__main__": print "Cache self test" apt_pkg.init() - c = Cache() - print c.has_key("aptitudex") - p = c["aptitude"] - print p.Name() - print len(c) + #c = Cache() + #print c.has_key("aptitudex") + #p = c["aptitude"] + #print p.Name() + #print len(c) + + #for pkg in c.keys(): + # x= c[pkg].Name() + c = FilteredCache() + c.Upgrade() + c.AddFilter(MarkedChangesFilter()) for pkg in c.keys(): - x= c[pkg].Name() + print c[pkg].Name() + |
