rpm 5.3.12
python/spec-py.c
Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #include <rpmiotypes.h>
00008 #include <rpmio.h>
00009 #include "spec-py.h"
00010 
00037 static void 
00038 spec_dealloc(specObject * s) 
00039     /*@modifies s @*/
00040 {
00041     if (s->spec)
00042         s->spec = freeSpec(s->spec);
00043     PyObject_Del(s);
00044 }
00045 
00046 static int
00047 spec_print(specObject * s)
00048 {
00049     return 0;
00050 }
00051 
00052 /* XXX TODO return something sensible if spec exists but component (eg %clean)
00053  * does not. Possibly "" or None */
00054 
00055 static PyObject * 
00056 spec_get_buildroot(specObject * s) 
00057     /*@*/
00058 {
00059     Spec spec = specFromSpec(s);
00060     PyObject * result = NULL;
00061     const char * buildRootURL = rpmExpand("%{?buildroot}", NULL);
00062     if (spec != NULL && *buildRootURL)
00063         result = Py_BuildValue("s", buildRootURL);
00064     buildRootURL = _free(buildRootURL);
00065     return result;
00066 }
00067 
00068 static PyObject * 
00069 spec_get_prep(specObject * s) 
00070     /*@*/
00071 {
00072     Spec spec = specFromSpec(s);
00073     return (spec != NULL && spec->prep != NULL)
00074         ? Py_BuildValue("s", rpmiobStr(spec->prep)) : NULL;
00075 }
00076 
00077 static PyObject * 
00078 spec_get_build(specObject * s) 
00079     /*@*/
00080 {
00081     Spec spec = specFromSpec(s);
00082     return (spec != NULL && spec->build != NULL)
00083         ? Py_BuildValue("s", rpmiobStr(spec->build)) : NULL;
00084 }
00085 
00086 static PyObject * 
00087 spec_get_install(specObject * s) 
00088     /*@*/
00089 {
00090     Spec spec = specFromSpec(s);
00091     return (spec != NULL && spec->install != NULL)
00092         ? Py_BuildValue("s", rpmiobStr(spec->install)) : NULL;
00093 }
00094 
00095 static PyObject * 
00096 spec_get_check(specObject * s) 
00097     /*@*/
00098 {
00099     Spec spec = specFromSpec(s);
00100     return (spec != NULL && spec->check != NULL)
00101         ? Py_BuildValue("s", rpmiobStr(spec->check)) : NULL;
00102 }
00103 
00104 static PyObject * 
00105 spec_get_clean(specObject * s) 
00106     /*@*/
00107 {
00108     Spec spec = specFromSpec(s);
00109     return (spec != NULL && spec->clean != NULL)
00110         ? Py_BuildValue("s", rpmiobStr(spec->clean)) : NULL;
00111 }
00112 
00113 static PyObject *
00114 spec_get_sources(specObject *s)
00115     /*@*/
00116 {
00117     struct Source * source;
00118     PyObject *sourceList, *srcUrl;
00119     Spec spec;
00120     const char * fullSource;
00121 
00122     sourceList = PyList_New(0);
00123     spec = specFromSpec(s);
00124     if ( spec != NULL) {
00125         source = spec->sources;
00126 
00127          while (source != NULL) {
00128             fullSource = source->fullSource;
00129             srcUrl = Py_BuildValue("(sii)", fullSource, source->num, source->flags);
00130             PyList_Append(sourceList, srcUrl);
00131             source = source->next;
00132         } 
00133 
00134         return PyList_AsTuple(sourceList);
00135     }
00136     else {
00137         return NULL;
00138     }
00139 
00140 }
00141 
00144  /*@unchecked@*/ /*@observer@*/
00145 static char spec_doc[] = "RPM Spec file object";
00146 
00147 /*@-fullinitblock@*/
00148 /*@unchecked@*/ /*@observer@*/
00149 static PyMethodDef spec_Spec_methods[] = {
00150     {"sources",   (PyCFunction) spec_get_sources, METH_VARARGS,  NULL },
00151     {"prep",   (PyCFunction) spec_get_prep, METH_VARARGS,  NULL },
00152     {"build",   (PyCFunction) spec_get_build, METH_VARARGS,  NULL },
00153     {"install",   (PyCFunction) spec_get_install, METH_VARARGS,  NULL },
00154     {"check",   (PyCFunction) spec_get_check, METH_VARARGS,  NULL },
00155     {"clean",   (PyCFunction) spec_get_clean, METH_VARARGS,  NULL },
00156     {"buildRoot",   (PyCFunction) spec_get_buildroot, METH_VARARGS,  NULL },
00157     {NULL}  /* Sentinel */
00158 };
00159 /*@=fullinitblock@*/
00160 
00161 /*@-fullinitblock@*/
00162 PyTypeObject spec_Type = {
00163     PyObject_HEAD_INIT(&PyType_Type)
00164     0,                         /*ob_size*/
00165     "rpm.spec",               /*tp_name*/
00166     sizeof(specObject),        /*tp_basicsize*/
00167     0,                         /*tp_itemsize*/
00168     (destructor) spec_dealloc, /*tp_dealloc*/
00169     (printfunc) spec_print,    /*tp_print*/
00170     0,                         /*tp_getattr*/
00171     0,                         /*tp_setattr*/
00172     0,                         /*tp_compare*/
00173     0,                         /*tp_repr*/
00174     0,                         /*tp_as_number*/
00175     0,                         /*tp_as_sequence*/
00176     0,                         /*tp_as_mapping*/
00177     0,                         /*tp_hash */
00178     0,                         /*tp_call*/
00179     0,                         /*tp_str*/
00180     0,                         /*tp_getattro*/
00181     0,                         /*tp_setattro*/
00182     0,                         /*tp_as_buffer*/
00183     Py_TPFLAGS_DEFAULT,        /*tp_flags*/
00184     spec_doc,                  /* tp_doc */
00185     0,                         /* tp_traverse */
00186     0,                         /* tp_clear */
00187     0,                         /* tp_richcompare */
00188     0,                         /* tp_weaklistoffset */
00189     0,                         /* tp_iter */
00190     0,                         /* tp_iternext */
00191     spec_Spec_methods,         /* tp_methods */
00192     0,                         /* tp_members */
00193     0,                         /* tp_getset */
00194     0,                         /* tp_base */
00195     0,                         /* tp_dict */
00196     0,                         /* tp_descr_get */
00197     0,                         /* tp_descr_set */
00198     0,                         /* tp_dictoffset */
00199     0,                         /* tp_init */
00200     0,                         /* tp_alloc */
00201     0,                         /* tp_new */
00202     0,                         /* tp_free */
00203     0,                         /* tp_is_gc */
00204 };
00205 /*@=fullinitblock@*/
00206 
00207 Spec specFromSpec(specObject *s) 
00208 {
00209     return s->spec;
00210 }
00211 
00212 specObject *
00213 spec_Wrap(Spec spec) 
00214 {
00215     specObject * s = PyObject_New(specObject, &spec_Type);
00216     if (s == NULL)
00217         return NULL;
00218     s->spec = spec; 
00219     return s;
00220 }