From: Panu Matilainen Date: Mon, 28 Sep 2009 13:19:22 +0000 (+0300) Subject: Implement rpm.readHeaderFromFD() in python instead of C X-Git-Tag: tznext/4.11.0.1.tizen20130304~2664 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dca55d3781401eb0ddce2759770054db7629083a;p=tools%2Flibrpm-tizen.git Implement rpm.readHeaderFromFD() in python instead of C --- diff --git a/python/header-py.c b/python/header-py.c index 8467cfd..cdf86c9 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -617,50 +617,6 @@ rpmMergeHeadersFromFD(PyObject * self, PyObject * args, PyObject * kwds) Py_RETURN_NONE; } -PyObject * -rpmSingleHeaderFromFD(PyObject * self, PyObject * args, PyObject * kwds) -{ - FD_t fd; - int fileno; - off_t offset; - PyObject * tuple; - Header h; - char * kwlist[] = {"fd", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &fileno)) - return NULL; - - offset = lseek(fileno, 0, SEEK_CUR); - - fd = fdDup(fileno); - - if (!fd) { - PyErr_SetFromErrno(pyrpmError); - return NULL; - } - - Py_BEGIN_ALLOW_THREADS - h = headerRead(fd, HEADER_MAGIC_YES); - Py_END_ALLOW_THREADS - - Fclose(fd); - - tuple = PyTuple_New(2); - - if (h && tuple) { - PyTuple_SET_ITEM(tuple, 0, hdr_Wrap(&hdr_Type, h)); - PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(offset)); - h = headerFree(h); - } else { - Py_INCREF(Py_None); - Py_INCREF(Py_None); - PyTuple_SET_ITEM(tuple, 0, Py_None); - PyTuple_SET_ITEM(tuple, 1, Py_None); - } - - return tuple; -} - PyObject * versionCompare (PyObject * self, PyObject * args, PyObject * kwds) { hdrObject * h1, * h2; diff --git a/python/rpm/__init__.py b/python/rpm/__init__.py index f59dffa..ca501c6 100644 --- a/python/rpm/__init__.py +++ b/python/rpm/__init__.py @@ -5,6 +5,7 @@ This module enables you to manipulate rpms and the rpm database. """ import warnings +import os from _rpm import * import _rpm @@ -17,12 +18,14 @@ def headerLoad(*args, **kwds): warnings.warn("Use rpm.hdr() instead.", DeprecationWarning, stacklevel=2) return hdr(*args, **kwds) -def readHeaderListFromFD(fd, retrofit = True): +def _fdno(fd): if hasattr(fd, "fileno"): - fdno = fd.fileno() + return fd.fileno() else: - fdno = fd + return fd +def readHeaderListFromFD(fd, retrofit = True): + fdno = _fdno(fd) hlist = [] while 1: try: @@ -41,3 +44,13 @@ def readHeaderListFromFile(path): f.close() return hlist +def readHeaderFromFD(fd): + fdno = _fdno(fd) + offset = os.lseek(fdno, 0, os.SEEK_CUR) + try: + h = hdr(fdno) + except _rpm.error: + h = None + offset = None + + return (h, offset) diff --git a/python/rpmmodule.c b/python/rpmmodule.c index 63e2e65..ce3d848 100644 --- a/python/rpmmodule.c +++ b/python/rpmmodule.c @@ -156,8 +156,6 @@ static PyMethodDef rpmModuleMethods[] = { { "mergeHeaderListFromFD", (PyCFunction) rpmMergeHeadersFromFD, METH_VARARGS|METH_KEYWORDS, NULL }, - { "readHeaderFromFD", (PyCFunction) rpmSingleHeaderFromFD, METH_VARARGS|METH_KEYWORDS, - NULL }, { "setLogFile", (PyCFunction) setLogFile, METH_VARARGS|METH_KEYWORDS, NULL },