00001
00005 #include "system.h"
00006
00007 #include "spec-py.h"
00008
00036 static void
00037 spec_dealloc(specObject * s)
00038
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
00053
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
00160 static char spec_doc[] = "RPM Spec file object";
00161
00162
00163
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}
00172 };
00173
00174
00175
00176 PyTypeObject spec_Type = {
00177 PyObject_HEAD_INIT(&PyType_Type)
00178 0,
00179 "rpm.spec",
00180 sizeof(specObject),
00181 0,
00182 (destructor) spec_dealloc,
00183 (printfunc) spec_print,
00184 0,
00185 0,
00186 0,
00187 0,
00188 0,
00189 0,
00190 0,
00191 0,
00192 0,
00193 0,
00194 0,
00195 0,
00196 0,
00197 Py_TPFLAGS_DEFAULT,
00198 spec_doc,
00199 0,
00200 0,
00201 0,
00202 0,
00203 0,
00204 0,
00205 spec_Spec_methods,
00206 0,
00207 0,
00208 0,
00209 0,
00210 0,
00211 0,
00212 0,
00213 0,
00214 0,
00215 0,
00216 0,
00217 0,
00218 };
00219
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 }