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