Ticket #14: rpm-4.6.0-python-spec-headers.patch

File rpm-4.6.0-python-spec-headers.patch, 2.0 kB (added by eswierk, 3 years ago)

Implement spec file header methods

  • rpm-4.6.0-rc1/python/spec-py.c

    old new  
    55#include "system.h" 
    66 
    77#include "spec-py.h" 
     8#include "header-py.h" 
    89 
    910/** \ingroup python 
    1011 * \name Class: Rpmspec 
     
    147148 
    148149} 
    149150 
     151static PyObject * 
     152spec_get_sourceHeader(specObject *s) 
     153{ 
     154    rpmSpec spec; 
     155 
     156    spec = specFromSpec(s); 
     157    if (spec == NULL) { 
     158        return NULL; 
     159    } 
     160    if (!spec->sourceHeader) { 
     161        initSourceHeader(spec); 
     162    } 
     163    return (PyObject *) hdr_Wrap(spec->sourceHeader); 
     164} 
     165 
     166static PyObject * 
     167spec_get_packageHeaders(specObject *s) 
     168{ 
     169    rpmSpec spec; 
     170    PyObject *obj; 
     171    Package p; 
     172    int n; 
     173    char *srcname; 
     174 
     175    spec = specFromSpec(s); 
     176    if (spec == NULL) { 
     177        return NULL; 
     178    } 
     179    for (p = spec->packages, n = 0; p; p = p->next, n++) {} 
     180    obj = PyList_New(n); 
     181    if (obj == NULL) { 
     182        return NULL; 
     183    } 
     184    if (!spec->sourceHeader) { 
     185        initSourceHeader(spec); 
     186    } 
     187    srcname = headerFormat( 
     188          spec->sourceHeader, 
     189          spec->noSource ? "%{name}-%{version}-%{release}.nosrc.rpm" 
     190          : "%{name}-%{version}-%{release}.src.rpm", NULL); 
     191    for (p = spec->packages, n = 0; p; p = p->next, n++) { 
     192        headerPutString(p->header, RPMTAG_SOURCERPM, srcname); 
     193        PyList_SET_ITEM(obj, n, (PyObject *) hdr_Wrap(p->header)); 
     194    } 
     195    return obj; 
     196} 
     197 
    150198/** 
    151199 */ 
    152200 
     
    159207    {"install",   (PyCFunction) spec_get_install, METH_VARARGS,  NULL }, 
    160208    {"clean",   (PyCFunction) spec_get_clean, METH_VARARGS,  NULL }, 
    161209    {"buildRoot",   (PyCFunction) spec_get_buildroot, METH_VARARGS,  NULL }, 
     210    {"sourceHeader",   (PyCFunction) spec_get_sourceHeader, METH_VARARGS,  NULL }, 
     211    {"packageHeaders",   (PyCFunction) spec_get_packageHeaders, METH_VARARGS,  NULL }, 
    162212    {NULL}  /* Sentinel */ 
    163213}; 
    164214