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
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
00053
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
00145 static char spec_doc[] = "RPM Spec file object";
00146
00147
00148
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}
00158 };
00159
00160
00161
00162 PyTypeObject spec_Type = {
00163 PyObject_HEAD_INIT(&PyType_Type)
00164 0,
00165 "rpm.spec",
00166 sizeof(specObject),
00167 0,
00168 (destructor) spec_dealloc,
00169 (printfunc) spec_print,
00170 0,
00171 0,
00172 0,
00173 0,
00174 0,
00175 0,
00176 0,
00177 0,
00178 0,
00179 0,
00180 0,
00181 0,
00182 0,
00183 Py_TPFLAGS_DEFAULT,
00184 spec_doc,
00185 0,
00186 0,
00187 0,
00188 0,
00189 0,
00190 0,
00191 spec_Spec_methods,
00192 0,
00193 0,
00194 0,
00195 0,
00196 0,
00197 0,
00198 0,
00199 0,
00200 0,
00201 0,
00202 0,
00203 0,
00204 };
00205
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 }