• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

python/spec-py.c

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

Generated on Mon Nov 29 2010 05:18:46 for rpm by  doxygen 1.7.2