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
00055
00056 static PyObject *
00057 rpmte_Debug( rpmteObject * s, PyObject * args, PyObject * kwds)
00058
00059
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
00071 static PyObject *
00072 rpmte_TEType(rpmteObject * s)
00073
00074 {
00075 return Py_BuildValue("i", rpmteType(s->te));
00076 }
00077
00078
00079 static PyObject *
00080 rpmte_N(rpmteObject * s)
00081
00082 {
00083 return Py_BuildValue("s", rpmteN(s->te));
00084 }
00085
00086
00087 static PyObject *
00088 rpmte_E(rpmteObject * s)
00089
00090 {
00091 return Py_BuildValue("s", rpmteE(s->te));
00092 }
00093
00094
00095 static PyObject *
00096 rpmte_V(rpmteObject * s)
00097
00098 {
00099 return Py_BuildValue("s", rpmteV(s->te));
00100 }
00101
00102
00103 static PyObject *
00104 rpmte_R(rpmteObject * s)
00105
00106 {
00107 return Py_BuildValue("s", rpmteR(s->te));
00108 }
00109
00110
00111 static PyObject *
00112 rpmte_A(rpmteObject * s)
00113
00114 {
00115 return Py_BuildValue("s", rpmteA(s->te));
00116 }
00117
00118
00119 static PyObject *
00120 rpmte_O(rpmteObject * s)
00121
00122 {
00123 return Py_BuildValue("s", rpmteO(s->te));
00124 }
00125
00126
00127 static PyObject *
00128 rpmte_NEVR(rpmteObject * s)
00129
00130 {
00131 return Py_BuildValue("s", rpmteNEVR(s->te));
00132 }
00133
00134
00135 static PyObject *
00136 rpmte_Color(rpmteObject * s)
00137
00138 {
00139 return Py_BuildValue("i", rpmteColor(s->te));
00140 }
00141
00142
00143 static PyObject *
00144 rpmte_PkgFileSize(rpmteObject * s)
00145
00146 {
00147 return Py_BuildValue("i", rpmtePkgFileSize(s->te));
00148 }
00149
00150
00151 static PyObject *
00152 rpmte_Depth(rpmteObject * s)
00153
00154 {
00155 return Py_BuildValue("i", rpmteDepth(s->te));
00156 }
00157
00158
00159 static PyObject *
00160 rpmte_Npreds(rpmteObject * s)
00161
00162 {
00163 return Py_BuildValue("i", rpmteNpreds(s->te));
00164 }
00165
00166
00167 static PyObject *
00168 rpmte_Degree(rpmteObject * s)
00169
00170 {
00171 return Py_BuildValue("i", rpmteDegree(s->te));
00172 }
00173
00174
00175 static PyObject *
00176 rpmte_Parent(rpmteObject * s)
00177
00178 {
00179 return Py_BuildValue("i", rpmteParent(s->te));
00180 }
00181
00182
00183 static PyObject *
00184 rpmte_Tree(rpmteObject * s)
00185
00186 {
00187 return Py_BuildValue("i", rpmteTree(s->te));
00188 }
00189
00190
00191 static PyObject *
00192 rpmte_AddedKey(rpmteObject * s)
00193
00194 {
00195 return Py_BuildValue("i", rpmteAddedKey(s->te));
00196 }
00197
00198
00199 static PyObject *
00200 rpmte_DependsOnKey(rpmteObject * s)
00201
00202 {
00203 return Py_BuildValue("i", rpmteDependsOnKey(s->te));
00204 }
00205
00206
00207 static PyObject *
00208 rpmte_DBOffset(rpmteObject * s)
00209
00210 {
00211 return Py_BuildValue("i", rpmteDBOffset(s->te));
00212 }
00213
00214
00215 static PyObject *
00216 rpmte_Key(rpmteObject * s)
00217
00218
00219 {
00220 PyObject * Key;
00221
00222
00223 Key = (PyObject *) rpmteKey(s->te);
00224 if (Key == NULL)
00225 Key = Py_None;
00226 Py_INCREF(Key);
00227 return Key;
00228 }
00229
00230
00231 static PyObject *
00232 rpmte_DS(rpmteObject * s, PyObject * args, PyObject * kwds)
00233
00234
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
00264 static PyObject *
00265 rpmte_FI(rpmteObject * s, PyObject * args, PyObject * kwds)
00266
00267
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
00299
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}
00357 };
00358
00359
00360
00361
00362 static int
00363 rpmte_print(rpmteObject * s, FILE * fp, int flags)
00364
00365
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
00394 static char rpmte_doc[] =
00395 "";
00396
00399
00400 PyTypeObject rpmte_Type = {
00401 PyObject_HEAD_INIT(&PyType_Type)
00402 0,
00403 "rpm.te",
00404 sizeof(rpmteObject),
00405 0,
00406 (destructor)0,
00407 (printfunc) rpmte_print,
00408 (getattrfunc)0,
00409 (setattrfunc)0,
00410 0,
00411 0,
00412 0,
00413 0,
00414 0,
00415 0,
00416 0,
00417 0,
00418 (getattrofunc) rpmte_getattro,
00419 (setattrofunc) rpmte_setattro,
00420 0,
00421 Py_TPFLAGS_DEFAULT,
00422 rpmte_doc,
00423 #if Py_TPFLAGS_HAVE_ITER
00424 0,
00425 0,
00426 0,
00427 0,
00428 0,
00429 0,
00430 rpmte_methods,
00431 0,
00432 0,
00433 0,
00434 0,
00435 0,
00436 0,
00437 0,
00438 0,
00439 0,
00440 0,
00441 0,
00442 0,
00443 #endif
00444 };
00445
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 }