--- rpm-5.4.5/python/spec-py.c.py_macros~ 2012-03-01 22:55:19.592995392 +0100 +++ rpm-5.4.5/python/spec-py.c 2012-03-01 22:56:02.081016570 +0100 @@ -6,6 +6,8 @@ #include #include +#define _MACRO_INTERNAL +#include #include "spec-py.h" /** \ingroup python @@ -146,6 +148,50 @@ spec_get_sources(specObject *s) } +static PyObject * +spec_get_macros(specObject *s) + /*@*/ +{ + MacroContext mc; + PyObject *macroDict; + Spec spec; + + macroDict = PyDict_New(); + if (!macroDict) { + return NULL; + } + spec = specFromSpec(s); + if ( spec != NULL) { + mc = spec->macros; + if (mc->macroTable != NULL) { + int i; + for (i = 0; i < mc->firstFree; i++) { + MacroEntry me; + PyObject *macro; + if ((me = mc->macroTable[i]) == NULL) { + /* XXX this should never happen */ + continue; + } + macro = PyDict_New(); + + PyMapping_SetItemString(macro, "used", PyInt_FromLong(me->used)); + PyMapping_SetItemString(macro, "level", PyInt_FromLong(me->level)); + if (me->opts && *me->opts) + PyMapping_SetItemString(macro, "opts", PyString_FromString(me->opts)); + if (me->body && *me->body) + PyMapping_SetItemString(macro, "body", PyString_FromString(me->body)); + PyMapping_SetItemString(macroDict, strdup(me->name), macro); + } + } + + return macroDict; + } + else { + return NULL; + } + +} + /** */ /*@unchecked@*/ /*@observer@*/ @@ -161,6 +207,7 @@ static PyMethodDef spec_Spec_methods[] = {"check", (PyCFunction) spec_get_check, METH_VARARGS, NULL }, {"clean", (PyCFunction) spec_get_clean, METH_VARARGS, NULL }, {"buildRoot", (PyCFunction) spec_get_buildroot, METH_VARARGS, NULL }, + {"macros", (PyCFunction) spec_get_macros, METH_VARARGS, NULL }, {NULL} /* Sentinel */ }; /*@=fullinitblock@*/