summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-11-19 10:51:23 +0200
committerPanu Matilainen <pmatilai@redhat.com>2009-11-19 10:51:23 +0200
commit71eeeb8d5e18ac6f6b349b09fd22fe2c650f8beb (patch)
tree1b709f8cad6bc8919f0203682d083600c17942d5
parent4beda5ab2676d6b007034b6f9906724c813fce68 (diff)
downloadrpm-71eeeb8d5e18ac6f6b349b09fd22fe2c650f8beb.tar.gz
rpm-71eeeb8d5e18ac6f6b349b09fd22fe2c650f8beb.tar.bz2
rpm-71eeeb8d5e18ac6f6b349b09fd22fe2c650f8beb.zip
Add spec package type with access to headers to python rpmb module
- permits python to access parsed headers from spec files - ticket #14, RhBug:462726
-rw-r--r--python/rpmbmodule.c3
-rw-r--r--python/spec-py.c100
-rw-r--r--python/spec-py.h4
3 files changed, 107 insertions, 0 deletions
diff --git a/python/rpmbmodule.c b/python/rpmbmodule.c
index 2a32a9572..9617c5819 100644
--- a/python/rpmbmodule.c
+++ b/python/rpmbmodule.c
@@ -13,6 +13,7 @@ static char rpmb__doc__[] =
static int prepareInitModule(void)
{
if (PyType_Ready(&spec_Type) < 0) return 0;
+ if (PyType_Ready(&specPkg_Type) < 0) return 0;
return 1;
}
@@ -21,6 +22,8 @@ static int initModule(PyObject *m)
{
Py_INCREF(&spec_Type);
PyModule_AddObject(m, "spec", (PyObject *) &spec_Type);
+ Py_INCREF(&specPkg_Type);
+ PyModule_AddObject(m, "specPkg", (PyObject *) &specPkg_Type);
return 1;
}
diff --git a/python/spec-py.c b/python/spec-py.c
index 5c488bba6..e162bb362 100644
--- a/python/spec-py.c
+++ b/python/spec-py.c
@@ -28,6 +28,82 @@
*
*/
+/* Header objects are in another module, some hoop jumping required... */
+static PyObject *makeHeader(Header h)
+{
+ PyObject *rpmmod = PyImport_ImportModuleNoBlock("rpm");
+ if (rpmmod == NULL) return NULL;
+
+ PyObject *ptr = PyCObject_FromVoidPtr(h, NULL);
+ PyObject *hdr = PyObject_CallMethod(rpmmod, "hdr", "(O)", ptr);
+ Py_XDECREF(ptr);
+ Py_XDECREF(rpmmod);
+ return hdr;
+}
+
+struct specPkgObject_s {
+ PyObject_HEAD
+ /*type specific fields */
+ Package pkg;
+};
+
+static char specPkg_doc[] =
+"";
+
+static PyObject * specpkg_get_header(specPkgObject *s, void *closure)
+{
+ Package pkg = s->pkg;
+ return makeHeader(pkg->header);
+}
+
+static PyGetSetDef specpkg_getseters[] = {
+ { "header", (getter) specpkg_get_header, NULL, NULL },
+ { NULL } /* sentinel */
+};
+
+PyTypeObject specPkg_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ "rpm.specpkg", /* tp_name */
+ sizeof(specPkgObject), /* tp_size */
+ 0, /* tp_itemsize */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ PyObject_GenericGetAttr, /* tp_getattro */
+ PyObject_GenericSetAttr, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
+ specPkg_doc, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ specpkg_getseters, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+};
+
struct specObject_s {
PyObject_HEAD
/*type specific fields */
@@ -107,6 +183,19 @@ static PyObject * spec_get_sources(specObject *s, void *closure)
}
+static PyObject * spec_get_packages(specObject *s, void *closure)
+{
+ rpmSpec spec = s->spec;
+ PyObject *pkgList = PyList_New(0);
+ Package pkg;
+
+ for (pkg = spec->packages; pkg; pkg = pkg->next) {
+ PyObject *po = specPkg_Wrap(&specPkg_Type, pkg);
+ PyList_Append(pkgList, po);
+ }
+ return pkgList;
+}
+
static char spec_doc[] = "RPM Spec file object";
static PyGetSetDef spec_getseters[] = {
@@ -116,6 +205,7 @@ static PyGetSetDef spec_getseters[] = {
{"install", (getter) spec_get_install, NULL, NULL },
{"clean", (getter) spec_get_clean, NULL, NULL },
{"buildRoot", (getter) spec_get_buildroot, NULL, NULL },
+ {"packages", (getter) spec_get_packages, NULL, NULL },
{NULL} /* Sentinel */
};
@@ -204,3 +294,13 @@ spec_Wrap(PyTypeObject *subtype, rpmSpec spec)
s->spec = spec;
return (PyObject *) s;
}
+
+PyObject * specPkg_Wrap(PyTypeObject *subtype, Package pkg)
+{
+ specPkgObject * s = (specPkgObject *)subtype->tp_alloc(subtype, 0);
+ if (s == NULL) return NULL;
+
+ s->pkg = pkg;
+ return (PyObject *) s;
+}
+
diff --git a/python/spec-py.h b/python/spec-py.h
index 4894d1af3..2faca3832 100644
--- a/python/spec-py.h
+++ b/python/spec-py.h
@@ -3,12 +3,16 @@
#include <rpm/rpmbuild.h>
+typedef struct specPkgObject_s specPkgObject;
typedef struct specObject_s specObject;
extern PyTypeObject spec_Type;
+extern PyTypeObject specPkg_Type;
#define specObject_Check(v) ((v)->ob_type == &spec_Type)
+#define specPkgObject_Check(v) ((v)->ob_type == &specPkg_Type)
PyObject * spec_Wrap(PyTypeObject *subtype, rpmSpec spec);
+PyObject * specPkg_Wrap(PyTypeObject *subtype, Package pkg);
#endif /* RPMPYTHON_SPEC */