From aff4a3d2c1280da136198463a51fff5026194048 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 20 Sep 2005 11:36:25 +0000 Subject: * added __iter__ support to apt/cache.py --- apt/cache.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'apt') diff --git a/apt/cache.py b/apt/cache.py index 83f0bd3d..973291c0 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -50,7 +50,6 @@ class Cache(object): self._records = apt_pkg.GetPkgRecords(self._cache) self._dict = {} - # build the packages dict if progress != None: progress.Op = "Building data structures" @@ -64,14 +63,21 @@ class Cache(object): if len(pkg.VersionList) > 0: self._dict[pkg.Name] = Package(self._cache, self._depcache, self._records, self, pkg) + i += 1 if progress != None: progress.done() self._runCallbacks("cache_post_open") def __getitem__(self, key): + """ look like a dictionary (get key) """ return self._dict[key] + def __iter__(self): + for pkgname in self._dict.keys(): + yield self._dict[pkgname] + raise StopIteration + def has_key(self, key): try: self._dict[key] -- cgit v1.2.3