--- rpm-5.4.16/python/spec-py.c~ 2016-03-16 17:22:00.000000000 +0200 +++ rpm-5.4.16/python/spec-py.c 2016-03-16 17:24:05.660232743 +0200 @@ -6,6 +6,8 @@ #include #include +#define _MACRO_INTERNAL +#include #include "spec-py.h" /** \ingroup python @@ -257,6 +257,50 @@ return makeHeader(spec->sourceHeader); } +static PyObject * +spec_get_macros(specObject *s, void *closure) + /*@*/ +{ + 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; + } + +} + static char spec_doc[] = "RPM Spec file object"; static PyGetSetDef spec_getseters[] = { @@ -269,6 +313,7 @@ {"buildRoot", (getter) spec_get_buildroot, NULL, NULL }, {"packages", (getter) spec_get_packages, NULL, NULL }, {"sourceHeader", (getter) spec_get_source_header, NULL, NULL }, + {"macros", (getter) spec_get_macros, NULL, NULL }, {NULL} /* Sentinel */ };