From 39910144460cafcc27d69026fd680fc8bd19c447 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 28 Jun 2007 15:10:22 +0200 Subject: * python/package.py: - added Record class that can be accessed like a dictionary and return it in candidateRecord and installedRecord (thanks to Alexander Sack for discussing this with me) * doc/examples/records.py: - added example how to use the new Records class --- apt/package.py | 21 +++++++++++++++++++-- debian/changelog | 11 +++++++++++ doc/examples/records.py | 12 ++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100755 doc/examples/records.py diff --git a/apt/package.py b/apt/package.py index b82f1aa0..4524a47d 100644 --- a/apt/package.py +++ b/apt/package.py @@ -40,6 +40,23 @@ class Dependency(object): def __init__(self, alternatives): self.or_dependencies = alternatives +class Record(object): + """ represents a pkgRecord, can be accessed like a + dictionary and gives the original package record + if accessed as a string """ + def __init__(self, s): + self._str = s + self._rec = apt_pkg.ParseSection(s) + def __str__(self): + return self._str + def __getitem__(self, key): + k = self._rec.get(key) + if k is None: + raise KeyError + return k + def has_key(self, key): + return self._rec.has_key(key) + class Package(object): """ This class represents a package in the cache """ @@ -244,14 +261,14 @@ class Package(object): " return the full pkgrecord as string of the candidate version " if not self._lookupRecord(True): return None - return self._records.Record + return Record(self._records.Record) candidateRecord = property(candidateRecord) def installedRecord(self): " return the full pkgrecord as string of the installed version " if not self._lookupRecord(False): return None - return self._records.Record + return Record(self._records.Record) installedRecord = property(installedRecord) # depcache states diff --git a/debian/changelog b/debian/changelog index 5536d8e1..8861ce26 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,14 @@ +python-apt (0.7.3) unstable; urgency=low + + * python/package.py: + - added Record class that can be accessed like a dictionary + and return it in candidateRecord and installedRecord + (thanks to Alexander Sack for discussing this with me) + * doc/examples/records.py: + - added example how to use the new Records class + + -- + python-apt (0.7.2) unstable; urgency=low * build against the new apt diff --git a/doc/examples/records.py b/doc/examples/records.py new file mode 100755 index 00000000..ef04b555 --- /dev/null +++ b/doc/examples/records.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +import apt + +cache = apt.Cache() + +for pkg in cache: + if not pkg.candidateRecord: + continue + if pkg.candidateRecord.has_key("Task"): + print "Pkg %s is part of '%s'" % (pkg.name, pkg.candidateRecord["Task"].split()) + #print pkg.candidateRecord -- cgit v1.2.3