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