Commit 9b12605a authored by Julian Andres Klode's avatar Julian Andres Klode

Add support for custom fields to apt_pkg.PackageRecords

parent ad247287
......@@ -1356,6 +1356,21 @@ Records (Release files, Packages, Sources)
# Now you can access the record
print(records.source_pkg) # == python-apt
.. describe:: section[key]
Return the value of the field at *key*. If *key* is not available,
raise :exc:`KeyError`.
Raises AttributeError if not yet looked up.
.. versionadded:: 1.7
.. describe:: key in section
Return ``True`` if *section* has a key *key*, else ``False``.
Raises AttributeError if not yet looked up.
.. versionadded:: 1.7
.. attribute:: filename
Return the field 'Filename' of the record. This is the path to the
......@@ -1436,6 +1451,11 @@ Records (Release files, Packages, Sources)
:class:`apt_pkg.TagSection` to parse the record and access the field
name.
.. deprecated:: 1.7
This property can be considered deprecated for simple string
lookups, as keys can now be looked up in the record itself.
Example::
section = apt_pkg.TagSection(records.record)
......
......@@ -180,6 +180,37 @@ static PyGetSetDef PkgRecordsGetSet[] = {
{}
};
static int PkgRecordsContains(PyObject *Self,PyObject *Arg)
{
PkgRecordsStruct &Struct = GetStruct(Self,"__contains__");
if (Struct.Last == nullptr)
return -1;
const char *Name = PyObject_AsString(Arg);
if (Name == nullptr)
return -1;
return !Struct.Last->RecordField(Name).empty();
}
static PyObject *PkgRecordsMap(PyObject *Self,PyObject *Arg)
{
PkgRecordsStruct &Struct = GetStruct(Self,"__contains__");
if (Struct.Last == nullptr)
return nullptr;
const char *Name = PyObject_AsString(Arg);
if (Name == nullptr)
return nullptr;
return CppPyString(Struct.Last->RecordField(Name));
}
PySequenceMethods PkgRecordsSeqMeth = {0,0,0,0,0,0,0,PkgRecordsContains,0,0};
PyMappingMethods PkgRecordsMapMeth = {0,PkgRecordsMap,0};
static PyObject *PkgRecordsNew(PyTypeObject *type,PyObject *Args,PyObject *kwds)
{
PyObject *Owner;
......@@ -213,8 +244,8 @@ PyTypeObject PyPackageRecords_Type =
0, // tp_compare
0, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
&PkgRecordsSeqMeth, // tp_as_sequence
&PkgRecordsMapMeth, // tp_as_mapping
0, // tp_hash
0, // tp_call
0, // tp_str
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment