python/rpmte-py.c

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

Generated on Fri Oct 12 08:44:54 2007 for rpm by  doxygen 1.5.2