summaryrefslogtreecommitdiff
path: root/apt
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2007-06-28 15:10:22 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2007-06-28 15:10:22 +0200
commit39910144460cafcc27d69026fd680fc8bd19c447 (patch)
tree82bed87b6cdfbbde1d925af90218b0be4ff68518 /apt
parenta1de071656261bb3e488c373cc8b6e9e62bf1a6c (diff)
downloadpython-apt-39910144460cafcc27d69026fd680fc8bd19c447.tar.gz
* 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
Diffstat (limited to 'apt')
-rw-r--r--apt/package.py21
1 files changed, 19 insertions, 2 deletions
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