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