- Main Page
- Related Pages
- Modules
- Data Structures
- Files

# python/rpmte-py.c

Go to the documentation of this file.

    00001
    00005 #include "system.h"
    00006
    00007 #include <rpmio.h>
    00008 #include <rpmcb.h>              /* XXX fnpyKey */
    00009 #include <rpmlib.h>
    00010
    00011 #include "header-py.h"  /* XXX tagNumFromPyObject */
    00012 #include "rpmds-py.h"
    00013 #include "rpmfi-py.h"
    00014 #include "rpmte-py.h"
    00015
    00016 #include "debug.h"
    00017
    00018 /*@access rpmte @*/
    00019 /*@access fnpyKey @*/
    00020
    00064
    00065 /*@null@*/
    00066 static PyObject *
    00067 rpmte_Debug(/*@unused@*/ rpmteObject * s, PyObject * args, PyObject * kwds)
    00068         /*@globals _Py_NoneStruct @*/
    00069         /*@modifies _Py_NoneStruct @*/
    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 /*@null@*/
    00081 static PyObject *
    00082 rpmte_TEType(rpmteObject * s)
    00083         /*@*/
    00084 {
    00085     return Py_BuildValue("i", rpmteType(s->te));
    00086 }
    00087
    00088 /*@null@*/
    00089 static PyObject *
    00090 rpmte_N(rpmteObject * s)
    00091         /*@*/
    00092 {
    00093     return Py_BuildValue("s", rpmteN(s->te));
    00094 }
    00095
    00096 /*@null@*/
    00097 static PyObject *
    00098 rpmte_E(rpmteObject * s)
    00099         /*@*/
    00100 {
    00101     return Py_BuildValue("s", rpmteE(s->te));
    00102 }
    00103
    00104 /*@null@*/
    00105 static PyObject *
    00106 rpmte_V(rpmteObject * s)
    00107         /*@*/
    00108 {
    00109     return Py_BuildValue("s", rpmteV(s->te));
    00110 }
    00111
    00112 /*@null@*/
    00113 static PyObject *
    00114 rpmte_R(rpmteObject * s)
    00115         /*@*/
    00116 {
    00117     return Py_BuildValue("s", rpmteR(s->te));
    00118 }
    00119
    00120 /*@null@*/
    00121 static PyObject *
    00122 rpmte_A(rpmteObject * s)
    00123         /*@*/
    00124 {
    00125     return Py_BuildValue("s", rpmteA(s->te));
    00126 }
    00127
    00128 /*@null@*/
    00129 static PyObject *
    00130 rpmte_O(rpmteObject * s)
    00131         /*@*/
    00132 {
    00133     return Py_BuildValue("s", rpmteO(s->te));
    00134 }
    00135
    00136 /*@null@*/
    00137 static PyObject *
    00138 rpmte_NEVR(rpmteObject * s)
    00139         /*@*/
    00140 {
    00141     return Py_BuildValue("s", rpmteNEVR(s->te));
    00142 }
    00143
    00144 /*@null@*/
    00145 static PyObject *
    00146 rpmte_NEVRA(rpmteObject * s)
    00147         /*@*/
    00148 {
    00149     return Py_BuildValue("s", rpmteNEVRA(s->te));
    00150 }
    00151
    00152 /*@null@*/
    00153 static PyObject *
    00154 rpmte_Pkgid(rpmteObject * s)
    00155         /*@*/
    00156 {
    00157     return Py_BuildValue("s", rpmtePkgid(s->te));
    00158 }
    00159
    00160 /*@null@*/
    00161 static PyObject *
    00162 rpmte_Hdrid(rpmteObject * s)
    00163         /*@*/
    00164 {
    00165     return Py_BuildValue("s", rpmteHdrid(s->te));
    00166 }
    00167
    00168 /*@null@*/
    00169 static PyObject *
    00170 rpmte_Color(rpmteObject * s)
    00171         /*@*/
    00172 {
    00173     return Py_BuildValue("i", rpmteColor(s->te));
    00174 }
    00175
    00176 /*@null@*/
    00177 static PyObject *
    00178 rpmte_PkgFileSize(rpmteObject * s)
    00179         /*@*/
    00180 {
    00181     return Py_BuildValue("i", rpmtePkgFileSize(s->te));
    00182 }
    00183
    00184 /*@null@*/
    00185 static PyObject *
    00186 rpmte_Breadth(rpmteObject * s)
    00187         /*@*/
    00188 {
    00189     return Py_BuildValue("i", rpmteBreadth(s->te));
    00190 }
    00191
    00192 /*@null@*/
    00193 static PyObject *
    00194 rpmte_Depth(rpmteObject * s)
    00195         /*@*/
    00196 {
    00197     return Py_BuildValue("i", rpmteDepth(s->te));
    00198 }
    00199
    00200 /*@null@*/
    00201 static PyObject *
    00202 rpmte_Npreds(rpmteObject * s)
    00203         /*@*/
    00204 {
    00205     return Py_BuildValue("i", rpmteNpreds(s->te));
    00206 }
    00207
    00208 /*@null@*/
    00209 static PyObject *
    00210 rpmte_Degree(rpmteObject * s)
    00211         /*@*/
    00212 {
    00213     return Py_BuildValue("i", rpmteDegree(s->te));
    00214 }
    00215
    00216 /*@null@*/
    00217 static PyObject *
    00218 rpmte_Parent(rpmteObject * s)
    00219         /*@*/
    00220 {
    00221     return Py_BuildValue("i", rpmteParent(s->te));
    00222 }
    00223
    00224 /*@null@*/
    00225 static PyObject *
    00226 rpmte_Tree(rpmteObject * s)
    00227         /*@*/
    00228 {
    00229     return Py_BuildValue("i", rpmteTree(s->te));
    00230 }
    00231
    00232 /*@null@*/
    00233 static PyObject *
    00234 rpmte_AddedKey(rpmteObject * s)
    00235         /*@*/
    00236 {
    00237     return Py_BuildValue("i", rpmteAddedKey(s->te));
    00238 }
    00239
    00240 /*@null@*/
    00241 static PyObject *
    00242 rpmte_DBOffset(rpmteObject * s)
    00243         /*@*/
    00244 {
    00245     return Py_BuildValue("i", rpmteDBOffset(s->te));
    00246 }
    00247
    00248 /*@null@*/
    00249 static PyObject *
    00250 rpmte_Key(rpmteObject * s)
    00251         /*@globals _Py_NoneStruct @*/
    00252         /*@modifies _Py_NoneStruct @*/
    00253 {
    00254     PyObject * Key;
    00255
    00256     /* XXX how to insure that returned Key is a PyObject??? */
    00257     Key = (PyObject *) rpmteKey(s->te);
    00258     if (Key == NULL)
    00259         Key = Py_None;
    00260     Py_INCREF(Key);
    00261     return Key;
    00262 }
    00263
    00264 /*@null@*/
    00265 static PyObject *
    00266 rpmte_DS(rpmteObject * s, PyObject * args, PyObject * kwds)
    00267         /*@globals _Py_NoneStruct @*/
    00268         /*@modifies _Py_NoneStruct @*/
    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 /*@null@*/
    00293 static PyObject *
    00294 rpmte_FI(rpmteObject * s, PyObject * args, PyObject * kwds)
    00295         /*@globals _Py_NoneStruct @*/
    00296         /*@modifies _Py_NoneStruct @*/
    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 /*@-fullinitblock@*/
    00325 /*@unchecked@*/ /*@observer@*/
    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}           /* sentinel */
    00392 };
    00393 /*@=fullinitblock@*/
    00394
    00395 /* ---------- */
    00396
    00397 static int
    00398 rpmte_print(rpmteObject * s, FILE * fp, /*@unused@*/ int flags)
    00399         /*@globals fileSystem @*/
    00400         /*@modifies fp, fileSystem @*/
    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 /*@unchecked@*/ /*@observer@*/
    00429 static char rpmte_doc[] =
    00430 "";
    00431
    00434 /*@-fullinitblock@*/
    00435 PyTypeObject rpmte_Type = {
    00436         PyObject_HEAD_INIT(&PyType_Type)
    00437         0,                              /* ob_size */
    00438         "rpm.te",                       /* tp_name */
    00439         sizeof(rpmteObject),            /* tp_size */
    00440         0,                              /* tp_itemsize */
    00441         (destructor)0,                  /* tp_dealloc */
    00442         (printfunc) rpmte_print,        /* tp_print */
    00443         (getattrfunc)0,                 /* tp_getattr */
    00444         (setattrfunc)0,                 /* tp_setattr */
    00445         0,                              /* tp_compare */
    00446         0,                              /* tp_repr */
    00447         0,                              /* tp_as_number */
    00448         0,                              /* tp_as_sequence */
    00449         0,                              /* tp_as_mapping */
    00450         0,                              /* tp_hash */
    00451         0,                              /* tp_call */
    00452         0,                              /* tp_str */
    00453         (getattrofunc) rpmte_getattro,  /* tp_getattro */
    00454         (setattrofunc) rpmte_setattro,  /* tp_setattro */
    00455         0,                              /* tp_as_buffer */
    00456         Py_TPFLAGS_DEFAULT,             /* tp_flags */
    00457         rpmte_doc,                      /* tp_doc */
    00458 #if Py_TPFLAGS_HAVE_ITER
    00459         0,                              /* tp_traverse */
    00460         0,                              /* tp_clear */
    00461         0,                              /* tp_richcompare */
    00462         0,                              /* tp_weaklistoffset */
    00463         0,                              /* tp_iter */
    00464         0,                              /* tp_iternext */
    00465         rpmte_methods,                  /* tp_methods */
    00466         0,                              /* tp_members */
    00467         0,                              /* tp_getset */
    00468         0,                              /* tp_base */
    00469         0,                              /* tp_dict */
    00470         0,                              /* tp_descr_get */
    00471         0,                              /* tp_descr_set */
    00472         0,                              /* tp_dictoffset */
    00473         0,                              /* tp_init */
    00474         0,                              /* tp_alloc */
    00475         0,                              /* tp_new */
    00476         0,                              /* tp_free */
    00477         0,                              /* tp_is_gc */
    00478 #endif
    00479 };
    00480 /*@=fullinitblock@*/
    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 }