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
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
00054
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
00161 static char spec_doc[] = "RPM Spec file object";
00162
00163
00164
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}
00173 };
00174
00175
00176
00177 PyTypeObject spec_Type = {
00178 PyObject_HEAD_INIT(&PyType_Type)
00179 0,
00180 "rpm.spec",
00181 sizeof(specObject),
00182 0,
00183 (destructor) spec_dealloc,
00184 (printfunc) spec_print,
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 0,
00198 Py_TPFLAGS_DEFAULT,
00199 spec_doc,
00200 0,
00201 0,
00202 0,
00203 0,
00204 0,
00205 0,
00206 spec_Spec_methods,
00207 0,
00208 0,
00209 0,
00210 0,
00211 0,
00212 0,
00213 0,
00214 0,
00215 0,
00216 0,
00217 0,
00218 0,
00219 };
00220
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 }