summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-09-28 16:07:09 +0300
committerPanu Matilainen <pmatilai@redhat.com>2009-09-28 16:07:09 +0300
commit07710f3033b277ccb46decd84f994e88d5e6869a (patch)
treef964c7790b26c5a02e459017073a250893a2835d
parentf0e9245660100d3ce41692889899844f42feb7a4 (diff)
downloadrpm-07710f3033b277ccb46decd84f994e88d5e6869a.tar.gz
rpm-07710f3033b277ccb46decd84f994e88d5e6869a.tar.bz2
rpm-07710f3033b277ccb46decd84f994e88d5e6869a.zip
Implement rpm.readHeaderListFromFD() in python instead of C
-rw-r--r--python/header-py.c52
-rw-r--r--python/header-py.h3
-rw-r--r--python/rpm/__init__.py18
-rw-r--r--python/rpmmodule.c2
4 files changed, 18 insertions, 57 deletions
diff --git a/python/header-py.c b/python/header-py.c
index 755252eb3..8467cfd34 100644
--- a/python/header-py.c
+++ b/python/header-py.c
@@ -524,58 +524,6 @@ Header hdrGetHeader(hdrObject * s)
return s->h;
}
-PyObject * rpmReadHeaders (FD_t fd)
-{
- PyObject * list;
- Header h;
- PyObject * hdr;
-
- if (!fd) {
- PyErr_SetFromErrno(pyrpmError);
- return NULL;
- }
-
- list = PyList_New(0);
- Py_BEGIN_ALLOW_THREADS
- h = headerRead(fd, HEADER_MAGIC_YES);
- Py_END_ALLOW_THREADS
-
- while (h) {
- headerConvert(h, HEADERCONV_RETROFIT_V3);
- hdr = hdr_Wrap(&hdr_Type, h);
- if (PyList_Append(list, (PyObject *) hdr)) {
- Py_DECREF(list);
- Py_DECREF(hdr);
- return NULL;
- }
- Py_DECREF(hdr);
-
- h = headerFree(h); /* XXX ref held by hdr */
-
- Py_BEGIN_ALLOW_THREADS
- h = headerRead(fd, HEADER_MAGIC_YES);
- Py_END_ALLOW_THREADS
- }
-
- return list;
-}
-
-PyObject * rpmHeaderFromFD(PyObject * self, PyObject * args, PyObject * kwds)
-{
- FD_t fd;
- PyObject * list;
- char * kwlist[] = {"fd", NULL};
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kwlist,
- rpmFdFromPyObject, &fd))
- return NULL;
-
- list = rpmReadHeaders (fd);
- Fclose(fd);
-
- return list;
-}
-
/**
* This assumes the order of list matches the order of the new headers, and
* throws an exception if that isn't true.
diff --git a/python/header-py.h b/python/header-py.h
index 4c3d8abe1..faebc4823 100644
--- a/python/header-py.h
+++ b/python/header-py.h
@@ -26,10 +26,7 @@ PyObject * labelCompare (PyObject * self, PyObject * args);
PyObject * versionCompare (PyObject * self, PyObject * args, PyObject * kwds);
PyObject * rpmMergeHeadersFromFD(PyObject * self, PyObject * args, PyObject * kwds);
int rpmMergeHeaders(PyObject * list, FD_t fd, int matchTag);
-PyObject * rpmHeaderFromFile(PyObject * self, PyObject * args, PyObject * kwds);
-PyObject * rpmHeaderFromFD(PyObject * self, PyObject * args, PyObject * kwds);
PyObject * rpmSingleHeaderFromFD(PyObject * self, PyObject * args, PyObject * kwds);
-PyObject * rpmReadHeaders (FD_t fd);
PyObject * hdrLoad(PyObject * self, PyObject * args, PyObject * kwds);
#endif
diff --git a/python/rpm/__init__.py b/python/rpm/__init__.py
index bbce2368b..f59dffa23 100644
--- a/python/rpm/__init__.py
+++ b/python/rpm/__init__.py
@@ -17,6 +17,24 @@ def headerLoad(*args, **kwds):
warnings.warn("Use rpm.hdr() instead.", DeprecationWarning, stacklevel=2)
return hdr(*args, **kwds)
+def readHeaderListFromFD(fd, retrofit = True):
+ if hasattr(fd, "fileno"):
+ fdno = fd.fileno()
+ else:
+ fdno = fd
+
+ hlist = []
+ while 1:
+ try:
+ h = hdr(fdno)
+ if retrofit:
+ h.convert(HEADERCONV_RETROFIT_V3)
+ hlist.append(h)
+ except _rpm.error:
+ break
+
+ return hlist
+
def readHeaderListFromFile(path):
f = open(path)
hlist = readHeaderListFromFD(f)
diff --git a/python/rpmmodule.c b/python/rpmmodule.c
index 4328fd4db..63e2e65b8 100644
--- a/python/rpmmodule.c
+++ b/python/rpmmodule.c
@@ -156,8 +156,6 @@ static PyMethodDef rpmModuleMethods[] = {
{ "mergeHeaderListFromFD", (PyCFunction) rpmMergeHeadersFromFD, METH_VARARGS|METH_KEYWORDS,
NULL },
- { "readHeaderListFromFD", (PyCFunction) rpmHeaderFromFD, METH_VARARGS|METH_KEYWORDS,
- NULL },
{ "readHeaderFromFD", (PyCFunction) rpmSingleHeaderFromFD, METH_VARARGS|METH_KEYWORDS,
NULL },