00001
00005 #include "system.h"
00006
00007 #include "Python.h"
00008 #ifdef __LCLINT__
00009 #undef PyObject_HEAD
00010 #define PyObject_HEAD int _PyObjectHead;
00011 #endif
00012
00013 #include <rpmlib.h>
00014
00015 #include "header-py.h"
00016 #include "rpmds-py.h"
00017 #include "rpmfi-py.h"
00018 #include "rpmte-py.h"
00019
00020 #include "debug.h"
00021
00022
00023
00024
00061 static PyObject *
00062 rpmte_Debug( rpmteObject * s, PyObject * args)
00063
00064
00065 {
00066 if (!PyArg_ParseTuple(args, "i", &_rpmte_debug)) return NULL;
00067 Py_INCREF(Py_None);
00068 return Py_None;
00069 }
00070
00071 static PyObject *
00072 rpmte_TEType(rpmteObject * s, PyObject * args)
00073
00074 {
00075 if (!PyArg_ParseTuple(args, ":TEType")) return NULL;
00076 return Py_BuildValue("i", rpmteType(s->te));
00077 }
00078
00079 static PyObject *
00080 rpmte_N(rpmteObject * s, PyObject * args)
00081
00082 {
00083 if (!PyArg_ParseTuple(args, ":N")) return NULL;
00084 return Py_BuildValue("s", rpmteN(s->te));
00085 }
00086
00087 static PyObject *
00088 rpmte_E(rpmteObject * s, PyObject * args)
00089
00090 {
00091 if (!PyArg_ParseTuple(args, ":E")) return NULL;
00092 return Py_BuildValue("s", rpmteE(s->te));
00093 }
00094
00095 static PyObject *
00096 rpmte_V(rpmteObject * s, PyObject * args)
00097
00098 {
00099 if (!PyArg_ParseTuple(args, ":V")) return NULL;
00100 return Py_BuildValue("s", rpmteV(s->te));
00101 }
00102
00103 static PyObject *
00104 rpmte_R(rpmteObject * s, PyObject * args)
00105
00106 {
00107 if (!PyArg_ParseTuple(args, ":R")) return NULL;
00108 return Py_BuildValue("s", rpmteR(s->te));
00109 }
00110
00111 static PyObject *
00112 rpmte_A(rpmteObject * s, PyObject * args)
00113
00114 {
00115 if (!PyArg_ParseTuple(args, ":A")) return NULL;
00116 return Py_BuildValue("s", rpmteA(s->te));
00117 }
00118
00119 static PyObject *
00120 rpmte_O(rpmteObject * s, PyObject * args)
00121
00122 {
00123 if (!PyArg_ParseTuple(args, ":O")) return NULL;
00124 return Py_BuildValue("s", rpmteO(s->te));
00125 }
00126
00127 static PyObject *
00128 rpmte_NEVR(rpmteObject * s, PyObject * args)
00129
00130 {
00131 if (!PyArg_ParseTuple(args, ":NEVR")) return NULL;
00132 return Py_BuildValue("s", rpmteNEVR(s->te));
00133 }
00134
00135 static PyObject *
00136 rpmte_Color(rpmteObject * s, PyObject * args)
00137
00138 {
00139 if (!PyArg_ParseTuple(args, ":Color")) return NULL;
00140 return Py_BuildValue("i", rpmteColor(s->te));
00141 }
00142
00143 static PyObject *
00144 rpmte_PkgFileSize(rpmteObject * s, PyObject * args)
00145
00146 {
00147 if (!PyArg_ParseTuple(args, ":PkgFileSize")) return NULL;
00148 return Py_BuildValue("i", rpmtePkgFileSize(s->te));
00149 }
00150
00151 static PyObject *
00152 rpmte_Depth(rpmteObject * s, PyObject * args)
00153
00154 {
00155 if (!PyArg_ParseTuple(args, ":Depth")) return NULL;
00156 return Py_BuildValue("i", rpmteDepth(s->te));
00157 }
00158
00159 static PyObject *
00160 rpmte_Npreds(rpmteObject * s, PyObject * args)
00161
00162 {
00163 if (!PyArg_ParseTuple(args, ":Npreds")) return NULL;
00164 return Py_BuildValue("i", rpmteNpreds(s->te));
00165 }
00166
00167 static PyObject *
00168 rpmte_Degree(rpmteObject * s, PyObject * args)
00169
00170 {
00171 if (!PyArg_ParseTuple(args, ":Degree")) return NULL;
00172 return Py_BuildValue("i", rpmteDegree(s->te));
00173 }
00174
00175 static PyObject *
00176 rpmte_Parent(rpmteObject * s, PyObject * args)
00177
00178 {
00179 if (!PyArg_ParseTuple(args, ":Parent")) return NULL;
00180 return Py_BuildValue("i", rpmteParent(s->te));
00181 }
00182
00183 static PyObject *
00184 rpmte_Tree(rpmteObject * s, PyObject * args)
00185
00186 {
00187 if (!PyArg_ParseTuple(args, ":Tree")) return NULL;
00188 return Py_BuildValue("i", rpmteTree(s->te));
00189 }
00190
00191 static PyObject *
00192 rpmte_AddedKey(rpmteObject * s, PyObject * args)
00193
00194 {
00195 if (!PyArg_ParseTuple(args, ":AddedKey")) return NULL;
00196 return Py_BuildValue("i", rpmteAddedKey(s->te));
00197 }
00198
00199 static PyObject *
00200 rpmte_DependsOnKey(rpmteObject * s, PyObject * args)
00201
00202 {
00203 if (!PyArg_ParseTuple(args, ":DependsOnKey")) return NULL;
00204 return Py_BuildValue("i", rpmteDependsOnKey(s->te));
00205 }
00206
00207 static PyObject *
00208 rpmte_DBOffset(rpmteObject * s, PyObject * args)
00209
00210 {
00211 if (!PyArg_ParseTuple(args, ":DBOffset")) return NULL;
00212 return Py_BuildValue("i", rpmteDBOffset(s->te));
00213 }
00214
00215 static PyObject *
00216 rpmte_Key(rpmteObject * s, PyObject * args)
00217
00218
00219 {
00220 PyObject * Key;
00221
00222 if (!PyArg_ParseTuple(args, ":Key")) return NULL;
00223
00224 Key = (PyObject *) rpmteKey(s->te);
00225 if (Key == NULL) {
00226 Py_INCREF(Py_None);
00227 return Py_None;
00228 }
00229 return Key;
00230 }
00231
00232 static PyObject *
00233 rpmte_DS(rpmteObject * s, PyObject * args)
00234
00235
00236 {
00237 PyObject * TagN = NULL;
00238 rpmds ds;
00239 rpmTag tag;
00240
00241 if (!PyArg_ParseTuple(args, "O:DS", &TagN)) return NULL;
00242
00243 tag = tagNumFromPyObject(TagN);
00244 if (tag == -1) {
00245 PyErr_SetString(PyExc_TypeError, "unknown tag type");
00246 return NULL;
00247 }
00248
00249 ds = rpmteDS(s->te, tag);
00250 if (ds == NULL) {
00251 #ifdef DYING
00252 PyErr_SetString(PyExc_TypeError, "invalid ds tag");
00253 return NULL;
00254 #else
00255 Py_INCREF(Py_None);
00256 return Py_None;
00257 #endif
00258 }
00259 return (PyObject *) rpmds_Wrap(rpmdsLink(ds, "rpmte_DS"));
00260 }
00261
00262 static PyObject *
00263 rpmte_FI(rpmteObject * s, PyObject * args)
00264
00265
00266 {
00267 PyObject * TagN = NULL;
00268 rpmfi fi;
00269 rpmTag tag;
00270
00271 if (!PyArg_ParseTuple(args, "O:FI", &TagN)) return NULL;
00272
00273 tag = tagNumFromPyObject(TagN);
00274 if (tag == -1) {
00275 PyErr_SetString(PyExc_TypeError, "unknown tag type");
00276 return NULL;
00277 }
00278
00279 fi = rpmteFI(s->te, tag);
00280 if (fi == NULL) {
00281 #ifdef DYING
00282 PyErr_SetString(PyExc_TypeError, "invalid fi tag");
00283 return NULL;
00284 #else
00285 Py_INCREF(Py_None);
00286 return Py_None;
00287 #endif
00288 }
00289 return (PyObject *) rpmfi_Wrap(rpmfiLink(fi, "rpmte_FI"));
00290 }
00291
00294
00295
00296 static struct PyMethodDef rpmte_methods[] = {
00297 {"Debug", (PyCFunction)rpmte_Debug, METH_VARARGS,
00298 NULL},
00299 {"Type", (PyCFunction)rpmte_TEType, METH_VARARGS,
00300 "te.Type() -> Type\n\
00301 - Return element type (rpm.TR_ADDED | rpm.TR_REMOVED).\n" },
00302 {"N", (PyCFunction)rpmte_N, METH_VARARGS,
00303 "te.N() -> N\n\
00304 - Return element name.\n" },
00305 {"E", (PyCFunction)rpmte_E, METH_VARARGS,
00306 "te.E() -> E\n\
00307 - Return element epoch.\n" },
00308 {"V", (PyCFunction)rpmte_V, METH_VARARGS,
00309 "te.V() -> V\n\
00310 - Return element version.\n" },
00311 {"R", (PyCFunction)rpmte_R, METH_VARARGS,
00312 "te.R() -> R\n\
00313 - Return element release.\n" },
00314 {"A", (PyCFunction)rpmte_A, METH_VARARGS,
00315 "te.A() -> A\n\
00316 - Return element arch.\n" },
00317 {"O", (PyCFunction)rpmte_O, METH_VARARGS,
00318 "te.O() -> O\n\
00319 - Return element os.\n" },
00320 {"NEVR", (PyCFunction)rpmte_NEVR, METH_VARARGS,
00321 "te.NEVR() -> NEVR\n\
00322 - Return element name-version-release.\n" },
00323 {"Color",(PyCFunction)rpmte_Color, METH_VARARGS,
00324 NULL},
00325 {"PkgFileSize",(PyCFunction)rpmte_PkgFileSize, METH_VARARGS,
00326 NULL},
00327 {"Depth", (PyCFunction)rpmte_Depth, METH_VARARGS,
00328 NULL},
00329 {"Npreds", (PyCFunction)rpmte_Npreds, METH_VARARGS,
00330 NULL},
00331 {"Degree", (PyCFunction)rpmte_Degree, METH_VARARGS,
00332 NULL},
00333 {"Parent", (PyCFunction)rpmte_Parent, METH_VARARGS,
00334 NULL},
00335 {"Tree", (PyCFunction)rpmte_Tree, METH_VARARGS,
00336 NULL},
00337 {"AddedKey",(PyCFunction)rpmte_AddedKey, METH_VARARGS,
00338 NULL},
00339 {"DependsOnKey",(PyCFunction)rpmte_DependsOnKey, METH_VARARGS,
00340 NULL},
00341 {"DBOffset",(PyCFunction)rpmte_DBOffset, METH_VARARGS,
00342 NULL},
00343 {"Key", (PyCFunction)rpmte_Key, METH_VARARGS,
00344 NULL},
00345 {"DS", (PyCFunction)rpmte_DS, METH_VARARGS,
00346 "te.DS(TagN) -> DS\n\
00347 - Return the TagN dependency set (or None). TagN is one of\n\
00348 'Providename', 'Requirename', 'Obsoletename', 'Conflictname'\n" },
00349 {"FI", (PyCFunction)rpmte_FI, METH_VARARGS,
00350 "te.FI(TagN) -> FI\n\
00351 - Return the TagN dependency set (or None). TagN must be 'Basenames'.\n" },
00352 {NULL, NULL}
00353 };
00354
00355
00356
00357
00358 static int
00359 rpmte_print(rpmteObject * s, FILE * fp, int flags)
00360
00361
00362 {
00363 const char * tstr;
00364 if (!(s && s->te))
00365 return -1;
00366 switch (rpmteType(s->te)) {
00367 case TR_ADDED: tstr = "++"; break;
00368 case TR_REMOVED: tstr = "--"; break;
00369 default: tstr = "??"; break;
00370 }
00371 fprintf(fp, "%s %s %s", tstr, rpmteNEVR(s->te), rpmteA(s->te));
00372 return 0;
00373 }
00374
00377 static PyObject * rpmte_getattr(rpmteObject * o, char * name)
00378
00379 {
00380 return Py_FindMethod(rpmte_methods, (PyObject *) o, name);
00381 }
00382
00385
00386 static char rpmte_doc[] =
00387 "";
00388
00391
00392 PyTypeObject rpmte_Type = {
00393 PyObject_HEAD_INIT(&PyType_Type)
00394 0,
00395 "rpm.te",
00396 sizeof(rpmteObject),
00397 0,
00398 (destructor)0,
00399 (printfunc) rpmte_print,
00400 (getattrfunc) rpmte_getattr,
00401 (setattrfunc)0,
00402 0,
00403 0,
00404 0,
00405 0,
00406 0,
00407 0,
00408 0,
00409 0,
00410 0,
00411 0,
00412 0,
00413 Py_TPFLAGS_DEFAULT,
00414 rpmte_doc,
00415 #if Py_TPFLAGS_HAVE_ITER
00416 0,
00417 0,
00418 0,
00419 0,
00420 0,
00421 0,
00422 rpmte_methods,
00423 0,
00424 0,
00425 0,
00426 0,
00427 0,
00428 0,
00429 0,
00430 0,
00431 0,
00432 0,
00433 0,
00434 0,
00435 #endif
00436 };
00437
00438
00439 rpmteObject * rpmte_Wrap(rpmte te)
00440 {
00441 rpmteObject *s = PyObject_New(rpmteObject, &rpmte_Type);
00442 if (s == NULL)
00443 return NULL;
00444 s->te = te;
00445 return s;
00446 }