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 +++++++- debian/changelog | 4 +++- tests/apt-test.py | 3 +-- 3 files changed, 11 insertions(+), 4 deletions(-) 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] diff --git a/debian/changelog b/debian/changelog index df7bd0a0..a31244bb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,8 +8,10 @@ python-apt (0.6.14) unstable; urgency=low - support for "srcrecords.Files" added - always run "Restart" before performing a Lookup * export locking via: GetLock(),PkgSystem{Lock,UnLock} + * apt/cache.py: + - add __iter__ - -- + -- Michael Vogt Tue, 20 Sep 2005 13:24:31 +0200 python-apt (0.6.13) unstable; urgency=low diff --git a/tests/apt-test.py b/tests/apt-test.py index f1bc5593..6205cf60 100644 --- a/tests/apt-test.py +++ b/tests/apt-test.py @@ -7,8 +7,7 @@ if __name__ == "__main__": progress = apt.progress.OpTextProgress() cache = apt.Cache(progress) print cache - for name in cache.keys(): - pkg = cache[name] + for pkg in cache: if pkg.isUpgradable: pkg.markInstall() for pkg in cache.getChanges(): -- cgit v1.2.3