diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2005-05-09 12:59:08 +0000 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2005-05-09 12:59:08 +0000 |
| commit | ae3f10fba648644a568dab3e21480580eb21e8a1 (patch) | |
| tree | 4e7f64dc172c4813f926d8607672e28ce07f04bb /apt/cache.py | |
| parent | 5e4d32fbdcb6ab0bfe5326e09fea1c9ecd7ef98d (diff) | |
| download | python-apt-ae3f10fba648644a568dab3e21480580eb21e8a1.tar.gz | |
* more work on the native python apt interface
Diffstat (limited to 'apt/cache.py')
| -rw-r--r-- | apt/cache.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/apt/cache.py b/apt/cache.py new file mode 100644 index 00000000..e575745f --- /dev/null +++ b/apt/cache.py @@ -0,0 +1,60 @@ +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): + #dict.__init__(self) + self.open() + + def open(self) + self._cache = apt_pkg.GetCache() + self._depcache = apt_pkg.GetDepCache(self._cache) + self._records = apt_pkg.GetPkgRecords(self._cache) + self._depcache.Init() + self._dict = {} + + # build the packages dict + for pkg in self._cache.Packages: + self._dict[pkg.Name] = Package(self._cache, self._depcache, self._records, pkg) + + def __getitem__(self, key): + return self._dict[key] + + def has_key(self, key): + try: + self._dict[key] + except KeyError: + return False + return True + + def __len__(self): + return len(self._dict) + + def keys(self): + return self._dict.keys() + + def Upgrade(self, DistUpgrade=False): + self._depcache.Upgrade(DistUpgrade) + + def Commit(self, fprogress, iprogress): + self._depcache.Commit(fprogress, iprogress) + + def + +if __name__ == "__main__": + print "Cache self test" + apt_pkg.init() + c = Cache() + print c.has_key("aptitudex") + p = c["aptitude"] + print p.Name() + + for pkg in c.keys(): + x= c[pkg].Name() |
