From 1d2d0456890be9341f031d854a7feb69c87b2419 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 23 Sep 2009 11:41:20 +0300 Subject: [PATCH] Add write() method to python headers --- python/header-py.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/python/header-py.c b/python/header-py.c index 2ed8a7d..e7c6b6c 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -7,6 +7,7 @@ #include "header-py.h" #include "rpmds-py.h" +#include "rpmfd-py.h" #include "rpmfi-py.h" #include "debug.h" @@ -295,6 +296,30 @@ static PyObject *hdrConvert(hdrObject *self, PyObject *args, PyObject *kwds) return PyBool_FromLong(headerConvert(self->h, op)); } +static PyObject * hdrWrite(hdrObject *s, PyObject *args, PyObject *kwds) +{ + PyObject *fo = NULL; + char *kwlist[] = { "file", "magic", NULL }; + int magic = 1; + FD_t fd = NULL; + int rc; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &fo, &magic)) + return NULL; + + if ((fd = rpmFdFromPyObject(fo)) == NULL) return NULL; + + Py_BEGIN_ALLOW_THREADS; + rc = headerWrite(fd, s->h, magic ? HEADER_MAGIC_YES : HEADER_MAGIC_NO); + Py_END_ALLOW_THREADS; + + if (rc) PyErr_SetFromErrno(PyExc_IOError); + Fclose(fd); /* avoid messing up errno wrt above */ + if (rc) return NULL; + + Py_RETURN_NONE; +} + static PyObject * hdr_fiFromHeader(PyObject * s, PyObject * args, PyObject * kwds) { DEPRECATED_METHOD; @@ -333,7 +358,8 @@ static struct PyMethodDef hdr_methods[] = { NULL }, {"isSource", (PyCFunction)hdrIsSource, METH_NOARGS, NULL }, - + {"write", (PyCFunction)hdrWrite, METH_VARARGS|METH_KEYWORDS, + NULL }, {"dsOfHeader", (PyCFunction)hdr_dsOfHeader, METH_NOARGS, NULL}, {"dsFromHeader", (PyCFunction)hdr_dsFromHeader, METH_VARARGS|METH_KEYWORDS, -- 2.7.4