diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-10-12 14:43:44 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-10-12 14:43:44 +0300 |
commit | c6649c55a89a9a6803c1640961de6c2412e9eeb0 (patch) | |
tree | a1817fc4052236c9cf3d97a8648b787fee043859 | |
parent | bc716457e042e12f4e90efdabafe2cd69d3bff52 (diff) | |
download | librpm-tizen-c6649c55a89a9a6803c1640961de6c2412e9eeb0.tar.gz librpm-tizen-c6649c55a89a9a6803c1640961de6c2412e9eeb0.tar.bz2 librpm-tizen-c6649c55a89a9a6803c1640961de6c2412e9eeb0.zip |
Add limited support for modifying headers to python
- for now we only support tag deletion and assigning rpmtd objects, limiting
this to copying data from other headers
-rw-r--r-- | python/header-py.c | 20 | ||||
-rw-r--r-- | python/rpmtd-py.c | 11 | ||||
-rw-r--r-- | python/rpmtd-py.h | 4 |
3 files changed, 34 insertions, 1 deletions
diff --git a/python/header-py.c b/python/header-py.c index d2901220c..a06412775 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -456,6 +456,24 @@ static PyObject * hdr_subscript(hdrObject * s, PyObject * item) return hdrGetTag(s->h, tag); } +static int hdr_ass_subscript(hdrObject *s, PyObject *key, PyObject *value) +{ + rpmTag tag; + rpmtd td; + if (!tagNumFromPyObject(key, &tag)) return -1; + + if (value == NULL) { + /* XXX should failure raise key error? */ + headerDel(s->h, tag); + } else if (rpmtdFromPyObject(value, &td)) { + headerPut(s->h, td, HEADERPUT_DEFAULT); + } else { + PyErr_SetString(PyExc_TypeError, "rpm.td type expected"); + return -1; + } + return 0; +} + static PyObject * hdr_getattro(hdrObject * s, PyObject * n) { PyObject *res = PyObject_GenericGetAttr((PyObject *) s, n); @@ -477,7 +495,7 @@ static int hdr_setattro(PyObject * o, PyObject * n, PyObject * v) static PyMappingMethods hdr_as_mapping = { (lenfunc) 0, /* mp_length */ (binaryfunc) hdr_subscript, /* mp_subscript */ - (objobjargproc)0, /* mp_ass_subscript */ + (objobjargproc)hdr_ass_subscript,/* mp_ass_subscript */ }; static char hdr_doc[] = diff --git a/python/rpmtd-py.c b/python/rpmtd-py.c index 103910aef..e4549b0bf 100644 --- a/python/rpmtd-py.c +++ b/python/rpmtd-py.c @@ -178,3 +178,14 @@ PyTypeObject rpmtd_Type = { 0, /* tp_free */ 0, /* tp_is_gc */ }; + +int rpmtdFromPyObject(PyObject *obj, rpmtd *td) +{ + if (rpmtdObject_Check(obj)) { + *td = &(((rpmtdObject *)obj)->td); + return 1; + } else { + return 0; + } +} + diff --git a/python/rpmtd-py.h b/python/rpmtd-py.h index ac93b3a7a..4c95e89b4 100644 --- a/python/rpmtd-py.h +++ b/python/rpmtd-py.h @@ -5,6 +5,10 @@ typedef struct rpmtdObject_s rpmtdObject; extern PyTypeObject rpmtd_Type; +#define rpmtdObject_Check(v) ((v)->ob_type == &rpmtd_Type) + PyObject * rpmtd_AsPyobj(rpmtd td); +int rpmtdFromPyObject(PyObject *obj, rpmtd *td); + #endif |