From e78e4b71fc600cf251eead62cec6a7c07165e38b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 11 May 2005 14:13:16 +0000 Subject: * __init__ added for the apt module, IsInstalled() added --- apt/cache.py | 69 +++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 17 deletions(-) (limited to 'apt/cache.py') 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() + -- cgit v1.2.3