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 Py_INCREF(Py_None);
00226 return Py_None;
00227 }
00228 return Key;
00229 }
00230
00231
00232 static PyObject *
00233 rpmte_DS(rpmteObject * s, PyObject * args, PyObject * kwds)
00234
00235
00236 {
00237 PyObject * TagN = NULL;
00238 rpmds ds;
00239 rpmTag tag;
00240 char * kwlist[] = {"tag", NULL};
00241
00242 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:DS", kwlist, &TagN))
00243 return NULL;
00244
00245 tag = tagNumFromPyObject(TagN);
00246 if (tag == -1) {
00247 PyErr_SetString(PyExc_TypeError, "unknown tag type");
00248 return NULL;
00249 }
00250
00251 ds = rpmteDS(s->te, tag);
00252 if (ds == NULL) {
00253 #ifdef DYING
00254 PyErr_SetString(PyExc_TypeError, "invalid ds tag");
00255 return NULL;
00256 #else
00257 Py_INCREF(Py_None);
00258 return Py_None;
00259 #endif
00260 }
00261 return (PyObject *) rpmds_Wrap(rpmdsLink(ds, "rpmte_DS"));
00262 }
00263
00264
00265 static PyObject *
00266 rpmte_FI(rpmteObject * s, PyObject * args, PyObject * kwds)
00267
00268
00269 {
00270 PyObject * TagN = NULL;
00271 rpmfi fi;
00272 rpmTag tag;
00273 char * kwlist[] = {"tag", NULL};
00274
00275 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:FI", 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 fi = rpmteFI(s->te, tag);
00285 if (fi == NULL) {
00286 #ifdef DYING
00287 PyErr_SetString(PyExc_TypeError, "invalid fi tag");
00288 return NULL;
00289 #else
00290 Py_INCREF(Py_None);
00291 return Py_None;
00292 #endif
00293 }
00294 return (PyObject *) rpmfi_Wrap(rpmfiLink(fi, "rpmte_FI"));
00295 }
00296
00299
00300
00301 static struct PyMethodDef rpmte_methods[] = {
00302 {"Debug", (PyCFunction)rpmte_Debug, METH_VARARGS|METH_KEYWORDS,
00303 NULL},
00304 {"Type", (PyCFunction)rpmte_TEType, METH_NOARGS,
00305 "te.Type() -> Type\n\
00306 - Return element type (rpm.TR_ADDED | rpm.TR_REMOVED).\n" },
00307 {"N", (PyCFunction)rpmte_N, METH_NOARGS,
00308 "te.N() -> N\n\
00309 - Return element name.\n" },
00310 {"E", (PyCFunction)rpmte_E, METH_NOARGS,
00311 "te.E() -> E\n\
00312 - Return element epoch.\n" },
00313 {"V", (PyCFunction)rpmte_V, METH_NOARGS,
00314 "te.V() -> V\n\
00315 - Return element version.\n" },
00316 {"R", (PyCFunction)rpmte_R, METH_NOARGS,
00317 "te.R() -> R\n\
00318 - Return element release.\n" },
00319 {"A", (PyCFunction)rpmte_A, METH_NOARGS,
00320 "te.A() -> A\n\
00321 - Return element arch.\n" },
00322 {"O", (PyCFunction)rpmte_O, METH_NOARGS,
00323 "te.O() -> O\n\
00324 - Return element os.\n" },
00325 {"NEVR", (PyCFunction)rpmte_NEVR, METH_NOARGS,
00326 "te.NEVR() -> NEVR\n\
00327 - Return element name-version-release.\n" },
00328 {"Color",(PyCFunction)rpmte_Color, METH_NOARGS,
00329 NULL},
00330 {"PkgFileSize",(PyCFunction)rpmte_PkgFileSize, METH_NOARGS,
00331 NULL},
00332 {"Depth", (PyCFunction)rpmte_Depth, METH_NOARGS,
00333 NULL},
00334 {"Npreds", (PyCFunction)rpmte_Npreds, METH_NOARGS,
00335 NULL},
00336 {"Degree", (PyCFunction)rpmte_Degree, METH_NOARGS,
00337 NULL},
00338 {"Parent", (PyCFunction)rpmte_Parent, METH_NOARGS,
00339 NULL},
00340 {"Tree", (PyCFunction)rpmte_Tree, METH_NOARGS,
00341 NULL},
00342 {"AddedKey",(PyCFunction)rpmte_AddedKey, METH_NOARGS,
00343 NULL},
00344 {"DependsOnKey",(PyCFunction)rpmte_DependsOnKey, METH_NOARGS,
00345 NULL},
00346 {"DBOffset",(PyCFunction)rpmte_DBOffset, METH_NOARGS,
00347 NULL},
00348 {"Key", (PyCFunction)rpmte_Key, METH_NOARGS,
00349 NULL},
00350 {"DS", (PyCFunction)rpmte_DS, METH_VARARGS|METH_KEYWORDS,
00351 "te.DS(TagN) -> DS\n\
00352 - Return the TagN dependency set (or None). TagN is one of\n\
00353 'Providename', 'Requirename', 'Obsoletename', 'Conflictname'\n" },
00354 {"FI", (PyCFunction)rpmte_FI, METH_VARARGS|METH_KEYWORDS,
00355 "te.FI(TagN) -> FI\n\
00356 - Return the TagN dependency set (or None). TagN must be 'Basenames'.\n" },
00357 {NULL, NULL}
00358 };
00359
00360
00361
00362
00363 static int
00364 rpmte_print(rpmteObject * s, FILE * fp, int flags)
00365
00366
00367 {
00368 const char * tstr;
00369 if (!(s && s->te))
00370 return -1;
00371 switch (rpmteType(s->te)) {
00372 case TR_ADDED: tstr = "++"; break;
00373 case TR_REMOVED: tstr = "--"; break;
00374 default: tstr = "??"; break;
00375 }
00376 fprintf(fp, "%s %s %s", tstr, rpmteNEVR(s->te), rpmteA(s->te));
00377 return 0;
00378 }
00379
00380 static PyObject * rpmte_getattro(PyObject * o, PyObject * n)
00381
00382 {
00383 return PyObject_GenericGetAttr(o, n);
00384 }
00385
00386 static int rpmte_setattro(PyObject * o, PyObject * n, PyObject * v)
00387
00388 {
00389 return PyObject_GenericSetAttr(o, n, v);
00390 }
00391
00394
00395 static char rpmte_doc[] =
00396 "";
00397
00400
00401 PyTypeObject rpmte_Type = {
00402 PyObject_HEAD_INIT(&PyType_Type)
00403 0,
00404 "rpm.te",
00405 sizeof(rpmteObject),
00406 0,
00407 (destructor)0,
00408 (printfunc) rpmte_print,
00409 (getattrfunc)0,
00410 (setattrfunc)0,
00411 0,
00412 0,
00413 0,
00414 0,
00415 0,
00416 0,
00417 0,
00418 0,
00419 (getattrofunc) rpmte_getattro,
00420 (setattrofunc) rpmte_setattro,
00421 0,
00422 Py_TPFLAGS_DEFAULT,
00423 rpmte_doc,
00424 #if Py_TPFLAGS_HAVE_ITER
00425 0,
00426 0,
00427 0,
00428 0,
00429 0,
00430 0,
00431 rpmte_methods,
00432 0,
00433 0,
00434 0,
00435 0,
00436 0,
00437 0,
00438 0,
00439 0,
00440 0,
00441 0,
00442 0,
00443 0,
00444 #endif
00445 };
00446
00447
00448 rpmteObject * rpmte_Wrap(rpmte te)
00449 {
00450 rpmteObject *s = PyObject_New(rpmteObject, &rpmte_Type);
00451 if (s == NULL)
00452 return NULL;
00453 s->te = te;
00454 return s;
00455 }