Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

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

Generated on Mon Sep 26 13:36:16 2005 for rpm by  doxygen 1.3.9.1