python/spec-py.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #include "spec-py.h"
00008 
00036 static void 
00037 spec_dealloc(specObject * s) 
00038     /*@modifies s @*/
00039 {
00040         if (s->spec) {
00041             s->spec=freeSpec(s->spec);
00042         }
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     if (spec != NULL && spec->buildRootURL) {
00061         return Py_BuildValue("s", spec->buildRootURL);
00062     }
00063     else {
00064         return NULL;
00065     }
00066 }
00067 
00068 static PyObject * 
00069 spec_get_prep(specObject * s) 
00070     /*@*/
00071 {
00072     Spec spec = specFromSpec(s);
00073     if (spec != NULL && spec->prep) {
00074         StringBuf sb = newStringBuf();
00075         sb=spec->prep;
00076         return Py_BuildValue("s",getStringBuf(sb));
00077     }
00078      else {
00079          return NULL;
00080      }
00081 }
00082 
00083 static PyObject * 
00084 spec_get_build(specObject * s) 
00085     /*@*/
00086 {
00087     Spec spec = specFromSpec(s);
00088     if (spec != NULL && spec->build) {
00089         StringBuf sb = newStringBuf();
00090         sb=spec->build;
00091         return Py_BuildValue("s",getStringBuf(sb));
00092     }
00093      else {
00094          return NULL;
00095      }
00096 }
00097 
00098 static PyObject * 
00099 spec_get_install(specObject * s) 
00100     /*@*/
00101 {
00102     Spec spec = specFromSpec(s);
00103     if (spec != NULL && spec->install) {
00104         StringBuf sb = newStringBuf();
00105         sb=spec->install;
00106         return Py_BuildValue("s",getStringBuf(sb));
00107     }
00108      else {
00109          return NULL;
00110      }
00111 }
00112 
00113 static PyObject * 
00114 spec_get_clean(specObject * s) 
00115     /*@*/
00116 {
00117     Spec spec = specFromSpec(s);
00118     if (spec != NULL && spec->clean) {
00119         StringBuf sb = newStringBuf();
00120         sb=spec->clean;
00121         return Py_BuildValue("s",getStringBuf(sb));
00122     }
00123      else {
00124          return NULL;
00125      }
00126 }
00127 
00128 static PyObject *
00129 spec_get_sources(specObject *s)
00130     /*@*/
00131 {
00132     struct Source * source;
00133     PyObject *sourceList, *srcUrl;
00134     Spec spec;
00135     char * fullSource;
00136 
00137     sourceList = PyList_New(0);
00138     spec = specFromSpec(s);
00139     if ( spec != NULL) {
00140         source = spec->sources;
00141 
00142          while (source != NULL) {
00143             fullSource = source->fullSource;
00144             srcUrl = Py_BuildValue("(sii)", fullSource, source->num, source->flags);
00145             PyList_Append(sourceList, srcUrl);
00146             source=source->next;
00147         } 
00148 
00149         return PyList_AsTuple(sourceList);
00150     }
00151     else {
00152         return NULL;
00153     }
00154 
00155 }
00156 
00159  /*@unchecked@*/ /*@observer@*/
00160 static char spec_doc[] = "RPM Spec file object";
00161 
00162 /*@-fullinitblock@*/
00163 /*@unchecked@*/ /*@observer@*/
00164 static PyMethodDef spec_Spec_methods[] = {
00165     {"sources",   (PyCFunction) spec_get_sources, METH_VARARGS,  NULL },
00166     {"prep",   (PyCFunction) spec_get_prep, METH_VARARGS,  NULL },
00167     {"build",   (PyCFunction) spec_get_build, METH_VARARGS,  NULL },
00168     {"install",   (PyCFunction) spec_get_install, METH_VARARGS,  NULL },
00169     {"clean",   (PyCFunction) spec_get_clean, METH_VARARGS,  NULL },
00170     {"buildRoot",   (PyCFunction) spec_get_buildroot, METH_VARARGS,  NULL },
00171     {NULL}  /* Sentinel */
00172 };
00173 /*@=fullinitblock@*/
00174 
00175 /*@-fullinitblock@*/
00176 PyTypeObject spec_Type = {
00177     PyObject_HEAD_INIT(&PyType_Type)
00178     0,                         /*ob_size*/
00179     "rpm.spec",               /*tp_name*/
00180     sizeof(specObject),        /*tp_basicsize*/
00181     0,                         /*tp_itemsize*/
00182     (destructor) spec_dealloc, /*tp_dealloc*/
00183     (printfunc) spec_print,    /*tp_print*/
00184     0,                         /*tp_getattr*/
00185     0,                         /*tp_setattr*/
00186     0,                         /*tp_compare*/
00187     0,                         /*tp_repr*/
00188     0,                         /*tp_as_number*/
00189     0,                         /*tp_as_sequence*/
00190     0,                         /*tp_as_mapping*/
00191     0,                         /*tp_hash */
00192     0,                         /*tp_call*/
00193     0,                         /*tp_str*/
00194     0,                         /*tp_getattro*/
00195     0,                         /*tp_setattro*/
00196     0,                         /*tp_as_buffer*/
00197     Py_TPFLAGS_DEFAULT,        /*tp_flags*/
00198     spec_doc,                  /* tp_doc */
00199     0,                         /* tp_traverse */
00200     0,                         /* tp_clear */
00201     0,                         /* tp_richcompare */
00202     0,                         /* tp_weaklistoffset */
00203     0,                         /* tp_iter */
00204     0,                         /* tp_iternext */
00205     spec_Spec_methods,         /* tp_methods */
00206     0,                         /* tp_members */
00207     0,                         /* tp_getset */
00208     0,                         /* tp_base */
00209     0,                         /* tp_dict */
00210     0,                         /* tp_descr_get */
00211     0,                         /* tp_descr_set */
00212     0,                         /* tp_dictoffset */
00213     0,                         /* tp_init */
00214     0,                         /* tp_alloc */
00215     0,                         /* tp_new */
00216     0,                         /* tp_free */
00217     0,                         /* tp_is_gc */
00218 };
00219 /*@=fullinitblock@*/
00220 
00221 Spec specFromSpec(specObject *s) 
00222 {
00223     return s->spec;
00224 }
00225 
00226 specObject *
00227 spec_Wrap(Spec spec) 
00228 {
00229     specObject * s = PyObject_New(specObject, &spec_Type);
00230     if (s == NULL)
00231         return NULL;
00232     s->spec = spec; 
00233     return s;
00234 }

Generated on Tue Feb 19 22:53:21 2008 for rpm by  doxygen 1.5.1