00001
00005 #include "system.h"
00006
00007 #include <rpmlib.h>
00008
00009 #include "header-py.h"
00010 #include "rpmds-py.h"
00011
00012 #include "debug.h"
00013
00014
00015
00023 static
00024 void rpmds_ParseEVR(char * evr,
00025 const char ** ep,
00026 const char ** vp,
00027 const char ** rp)
00028
00029
00030 {
00031 const char *epoch;
00032 const char *version;
00033 const char *release;
00034 char *s, *se;
00035
00036 s = evr;
00037 while (*s && xisdigit(*s)) s++;
00038 se = strrchr(s, '-');
00039
00040 if (*s == ':') {
00041 epoch = evr;
00042 *s++ = '\0';
00043 version = s;
00044
00045 if (*epoch == '\0') epoch = "0";
00046
00047 } else {
00048 epoch = NULL;
00049 version = evr;
00050 }
00051 if (se) {
00052
00053 *se++ = '\0';
00054
00055 release = se;
00056 } else {
00057 release = NULL;
00058 }
00059
00060 if (ep) *ep = epoch;
00061 if (vp) *vp = version;
00062 if (rp) *rp = release;
00063 }
00064
00067 static int compare_values(const char *str1, const char *str2)
00068 {
00069 if (!str1 && !str2)
00070 return 0;
00071 else if (str1 && !str2)
00072 return 1;
00073 else if (!str1 && str2)
00074 return -1;
00075 return rpmvercmp(str1, str2);
00076 }
00077
00078 static int
00079 rpmds_compare(rpmdsObject * a, rpmdsObject * b)
00080
00081 {
00082 char *aEVR = xstrdup(rpmdsEVR(a->ds));
00083 const char *aE, *aV, *aR;
00084 char *bEVR = xstrdup(rpmdsEVR(b->ds));
00085 const char *bE, *bV, *bR;
00086 int rc;
00087
00088
00089 rpmds_ParseEVR(aEVR, &aE, &aV, &aR);
00090 rpmds_ParseEVR(bEVR, &bE, &bV, &bR);
00091
00092 rc = compare_values(aE, bE);
00093 if (!rc) {
00094 rc = compare_values(aV, bV);
00095 if (!rc)
00096 rc = compare_values(aR, bR);
00097 }
00098
00099 aEVR = _free(aEVR);
00100 bEVR = _free(bEVR);
00101
00102 return rc;
00103 }
00104
00105 static PyObject *
00106 rpmds_richcompare(rpmdsObject * a, rpmdsObject * b, int op)
00107
00108 {
00109 int rc;
00110
00111 switch (op) {
00112 case Py_NE:
00113
00114 rc = rpmdsCompare(a->ds, b->ds);
00115 rc = (rc < 0 ? -1 : (rc == 0 ? 1 : 0));
00116 break;
00117 case Py_LT:
00118 case Py_LE:
00119 case Py_GT:
00120 case Py_GE:
00121 case Py_EQ:
00122
00123 default:
00124 rc = -1;
00125 break;
00126 }
00127 return Py_BuildValue("i", rc);
00128 }
00129
00130 static PyObject *
00131 rpmds_iter(rpmdsObject * s)
00132
00133 {
00134 Py_INCREF(s);
00135 return (PyObject *)s;
00136 }
00137
00138
00139 static PyObject *
00140 rpmds_iternext(rpmdsObject * s)
00141
00142 {
00143 PyObject * result = NULL;
00144
00145
00146 if (!s->active) {
00147 s->ds = rpmdsInit(s->ds);
00148 s->active = 1;
00149 }
00150
00151
00152 if (rpmdsNext(s->ds) >= 0) {
00153 const char * N = rpmdsN(s->ds);
00154 const char * EVR = rpmdsEVR(s->ds);
00155 int tagN = rpmdsTagN(s->ds);
00156 int Flags = rpmdsFlags(s->ds);
00157
00158
00159 if (N != NULL) N = xstrdup(N);
00160 if (EVR != NULL) EVR = xstrdup(EVR);
00161
00162 result = (PyObject *)rpmds_Wrap( rpmdsSingle(tagN, N, EVR, Flags) );
00163 } else
00164 s->active = 0;
00165
00166 return result;
00167 }
00168
00173
00174
00175 static PyObject *
00176 rpmds_Next(rpmdsObject * s)
00177
00178
00179 {
00180 PyObject * result;
00181
00182 result = rpmds_iternext(s);
00183
00184 if (result == NULL) {
00185 Py_INCREF(Py_None);
00186 return Py_None;
00187 }
00188 return result;
00189 }
00190
00191
00192 static PyObject *
00193 rpmds_Debug( rpmdsObject * s, PyObject * args, PyObject * kwds)
00194
00195
00196 {
00197 char * kwlist[] = {"debugLevel", NULL};
00198
00199 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &_rpmds_debug))
00200 return NULL;
00201
00202 Py_INCREF(Py_None);
00203 return Py_None;
00204 }
00205
00206
00207 static PyObject *
00208 rpmds_Count(rpmdsObject * s)
00209
00210 {
00211 return Py_BuildValue("i", rpmdsCount(s->ds));
00212 }
00213
00214
00215 static PyObject *
00216 rpmds_Ix(rpmdsObject * s)
00217
00218 {
00219 return Py_BuildValue("i", rpmdsIx(s->ds));
00220 }
00221
00222
00223 static PyObject *
00224 rpmds_DNEVR(rpmdsObject * s)
00225
00226 {
00227 return Py_BuildValue("s", rpmdsDNEVR(s->ds));
00228 }
00229
00230
00231 static PyObject *
00232 rpmds_N(rpmdsObject * s)
00233
00234 {
00235 return Py_BuildValue("s", rpmdsN(s->ds));
00236 }
00237
00238
00239 static PyObject *
00240 rpmds_EVR(rpmdsObject * s)
00241
00242 {
00243 return Py_BuildValue("s", rpmdsEVR(s->ds));
00244 }
00245
00246
00247 static PyObject *
00248 rpmds_Flags(rpmdsObject * s)
00249
00250 {
00251 return Py_BuildValue("i", rpmdsFlags(s->ds));
00252 }
00253
00254
00255 static PyObject *
00256 rpmds_BT(rpmdsObject * s)
00257
00258 {
00259 return Py_BuildValue("i", (int) rpmdsBT(s->ds));
00260 }
00261
00262
00263 static PyObject *
00264 rpmds_TagN(rpmdsObject * s)
00265
00266 {
00267 return Py_BuildValue("i", rpmdsTagN(s->ds));
00268 }
00269
00270
00271 static PyObject *
00272 rpmds_Color(rpmdsObject * s)
00273
00274 {
00275 return Py_BuildValue("i", rpmdsColor(s->ds));
00276 }
00277
00278
00279 static PyObject *
00280 rpmds_Refs(rpmdsObject * s)
00281
00282 {
00283 return Py_BuildValue("i", rpmdsRefs(s->ds));
00284 }
00285
00286
00287 static PyObject *
00288 rpmds_Result(rpmdsObject * s)
00289
00290 {
00291 return Py_BuildValue("i", rpmdsResult(s->ds));
00292 }
00293
00294 static PyObject *
00295 rpmds_SetNoPromote(rpmdsObject * s, PyObject * args, PyObject * kwds)
00296
00297 {
00298 int nopromote;
00299 char * kwlist[] = {"noPromote", NULL};
00300
00301 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:SetNoPromote", kwlist,
00302 &nopromote))
00303 return NULL;
00304
00305 return Py_BuildValue("i", rpmdsSetNoPromote(s->ds, nopromote));
00306 }
00307
00308
00309 static PyObject *
00310 rpmds_Notify(rpmdsObject * s, PyObject * args, PyObject * kwds)
00311
00312
00313 {
00314 const char * where;
00315 int rc;
00316 char * kwlist[] = {"location", "returnCode", NULL};
00317
00318 if (!PyArg_ParseTupleAndKeywords(args, kwds, "si:Notify", kwlist,
00319 &where, &rc))
00320 return NULL;
00321
00322 rpmdsNotify(s->ds, where, rc);
00323 Py_INCREF(Py_None);
00324 return Py_None;
00325 }
00326
00327
00328
00329 static PyObject *
00330 rpmds_Sort(rpmdsObject * s)
00331
00332
00333 {
00334 rpmds nds = NULL;
00335
00336 if (rpmdsMerge(&nds, s->ds) >= 0) {
00337 s->ds = rpmdsFree(s->ds);
00338 s->ds = nds;
00339 }
00340 Py_INCREF(Py_None);
00341 return Py_None;
00342 }
00343
00344
00345 static PyObject *
00346 rpmds_Find(rpmdsObject * s, PyObject * args, PyObject * kwds)
00347
00348 {
00349 PyObject * to = NULL;
00350 rpmdsObject * o;
00351 char * kwlist[] = {"element", NULL};
00352
00353 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:Find", kwlist, &to))
00354 return NULL;
00355
00356
00357 o = (rpmdsObject *)to;
00358
00359
00360 if (rpmdsIx(o->ds) == -1) rpmdsSetIx(o->ds, 0);
00361
00362 return Py_BuildValue("i", rpmdsFind(s->ds, o->ds));
00363 }
00364
00365
00366 static PyObject *
00367 rpmds_Merge(rpmdsObject * s, PyObject * args, PyObject * kwds)
00368
00369 {
00370 PyObject * to = NULL;
00371 rpmdsObject * o;
00372 char * kwlist[] = {"element", NULL};
00373
00374 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:Merge", kwlist, &to))
00375 return NULL;
00376
00377
00378 o = (rpmdsObject *)to;
00379 return Py_BuildValue("i", rpmdsMerge(&s->ds, o->ds));
00380 }
00381
00382
00383 static PyObject *
00384 rpmds_Search(rpmdsObject * s, PyObject * args, PyObject * kwds)
00385
00386 {
00387 PyObject * to = NULL;
00388 rpmdsObject * o;
00389 char * kwlist[] = {"element", NULL};
00390
00391 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:Merge", kwlist, &to))
00392 return NULL;
00393
00394
00395 o = (rpmdsObject *)to;
00396 return Py_BuildValue("i", rpmdsSearch(s->ds, o->ds));
00397 }
00398
00399 static PyObject *
00400 rpmds_Cpuinfo(rpmdsObject * s)
00401
00402 {
00403 rpmds ds = NULL;
00404 int xx;
00405
00406
00407 xx = rpmdsCpuinfo(&ds, NULL);
00408
00409 return (PyObject *) rpmds_Wrap( ds );
00410 }
00411
00412 static PyObject *
00413 rpmds_Rpmlib(rpmdsObject * s)
00414
00415 {
00416 rpmds ds = NULL;
00417 int xx;
00418
00419
00420 xx = rpmdsRpmlib(&ds, NULL);
00421
00422 return (PyObject *) rpmds_Wrap( ds );
00423 }
00424
00425 static PyObject *
00426 rpmds_Sysinfo(rpmdsObject * s)
00427
00428 {
00429 rpmPRCO PRCO = rpmdsNewPRCO(NULL);
00430 rpmds P = NULL;
00431 int xx;
00432
00433
00434 xx = rpmdsSysinfo(PRCO, NULL);
00435 P = rpmdsLink(rpmdsFromPRCO(PRCO, RPMTAG_PROVIDENAME), __FUNCTION__);
00436 PRCO = rpmdsFreePRCO(PRCO);
00437
00438 return (PyObject *) rpmds_Wrap( P );
00439 }
00440
00441 static PyObject *
00442 rpmds_Getconf(rpmdsObject * s)
00443
00444 {
00445 rpmds ds = NULL;
00446 int xx;
00447
00448
00449 xx = rpmdsGetconf(&ds, NULL);
00450
00451 return (PyObject *) rpmds_Wrap( ds );
00452 }
00453
00454 static PyObject *
00455 rpmds_Ldconfig(rpmdsObject * s)
00456
00457 {
00458 rpmPRCO PRCO = rpmdsNewPRCO(NULL);
00459 rpmds P = NULL;
00460 int xx;
00461
00462
00463 xx = rpmdsLdconfig(PRCO, NULL);
00464
00465 P = rpmdsLink(rpmdsFromPRCO(PRCO, RPMTAG_PROVIDENAME), __FUNCTION__);
00466 PRCO = rpmdsFreePRCO(PRCO);
00467 return (PyObject *) rpmds_Wrap( P );
00468 }
00469
00470 #ifdef NOTYET
00471 static PyObject *
00472 rpmds_Compare(rpmdsObject * s, PyObject * args, PyObject * kwds)
00473
00474 {
00475 PyObject * to = NULL;
00476 rpmdsObject * o;
00477 char * kwlist[] = {"other", NULL};
00478
00479 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:Compare", kwlist, &to))
00480 return NULL;
00481
00482
00483 o = (rpmdsObject *)to;
00484 return Py_BuildValue("i", rpmdsCompare(s->ds, o->ds));
00485 }
00486
00487
00488 static PyObject *
00489 rpmds_Problem(rpmdsObject * s)
00490
00491 {
00492 if (!PyArg_ParseTuple(args, ":Problem"))
00493 return NULL;
00494 Py_INCREF(Py_None);
00495 return Py_None;
00496 }
00497 #endif
00498
00501
00502
00503 static struct PyMethodDef rpmds_methods[] = {
00504 {"Debug", (PyCFunction)rpmds_Debug, METH_VARARGS|METH_KEYWORDS,
00505 NULL},
00506 {"Count", (PyCFunction)rpmds_Count, METH_NOARGS,
00507 "ds.Count -> Count - Return no. of elements.\n" },
00508 {"Ix", (PyCFunction)rpmds_Ix, METH_NOARGS,
00509 "ds.Ix -> Ix - Return current element index.\n" },
00510 {"DNEVR", (PyCFunction)rpmds_DNEVR, METH_NOARGS,
00511 "ds.DNEVR -> DNEVR - Return current DNEVR.\n" },
00512 {"N", (PyCFunction)rpmds_N, METH_NOARGS,
00513 "ds.N -> N - Return current N.\n" },
00514 {"EVR", (PyCFunction)rpmds_EVR, METH_NOARGS,
00515 "ds.EVR -> EVR - Return current EVR.\n" },
00516 {"Flags", (PyCFunction)rpmds_Flags, METH_NOARGS,
00517 "ds.Flags -> Flags - Return current Flags.\n" },
00518 {"BT", (PyCFunction)rpmds_BT, METH_NOARGS,
00519 "ds.BT -> BT - Return build time.\n" },
00520 {"TagN", (PyCFunction)rpmds_TagN, METH_NOARGS,
00521 "ds.TagN -> TagN - Return current TagN.\n" },
00522 {"Color", (PyCFunction)rpmds_Color, METH_NOARGS,
00523 "ds.Color -> Color - Return current Color.\n" },
00524 {"Refs", (PyCFunction)rpmds_Refs, METH_NOARGS,
00525 "ds.Refs -> Refs - Return current Refs.\n" },
00526 {"Result", (PyCFunction)rpmds_Result, METH_NOARGS,
00527 "ds.Result -> Result - Return current Result.\n" },
00528 {"next", (PyCFunction)rpmds_Next, METH_NOARGS,
00529 "ds.next() -> (N, EVR, Flags)\n\
00530 - Retrieve next dependency triple.\n" },
00531 {"SetNoPromote",(PyCFunction)rpmds_SetNoPromote, METH_VARARGS|METH_KEYWORDS,
00532 NULL},
00533 {"Notify", (PyCFunction)rpmds_Notify, METH_VARARGS|METH_KEYWORDS,
00534 NULL},
00535 {"Sort", (PyCFunction)rpmds_Sort, METH_NOARGS,
00536 "ds.Sort() -> None\n\
00537 - Sort the (N,EVR,Flags) elements in ds\n" },
00538 {"Find", (PyCFunction)rpmds_Find, METH_VARARGS|METH_KEYWORDS,
00539 "ds.Find(element) -> matching ds index (-1 on failure)\n\
00540 - Check for an exactly matching element in ds.\n\
00541 The current index in ds is positioned at matching member upon success.\n" },
00542 {"Merge", (PyCFunction)rpmds_Merge, METH_VARARGS|METH_KEYWORDS,
00543 "ds.Merge(elements) -> 0 on success\n\
00544 - Merge elements into ds, maintaining (N,EVR,Flags) sort order.\n" },
00545 {"Search", (PyCFunction)rpmds_Search, METH_VARARGS|METH_KEYWORDS,
00546 "ds.Search(element) -> matching ds index (-1 on failure)\n\
00547 - Check that element dependency range overlaps some member of ds.\n\
00548 The current index in ds is positioned at overlapping member upon success.\n" },
00549 {"Cpuinfo", (PyCFunction)rpmds_Cpuinfo, METH_NOARGS|METH_STATIC,
00550 "ds.Cpuinfo -> nds - Return /proc/cpuinfo dependency set.\n"},
00551 {"Rpmlib", (PyCFunction)rpmds_Rpmlib, METH_NOARGS|METH_STATIC,
00552 "ds.Rpmlib -> nds - Return internal rpmlib dependency set.\n"},
00553 {"Sysinfo", (PyCFunction)rpmds_Sysinfo, METH_NOARGS|METH_STATIC,
00554 "ds.Sysinfo -> nds - Return /etc/rpm/sysinfo dependency set.\n"},
00555 {"Getconf", (PyCFunction)rpmds_Getconf, METH_NOARGS|METH_STATIC,
00556 "ds.Getconf -> nds - Return getconf(1) dependency set.\n"},
00557 {"Ldconfig", (PyCFunction)rpmds_Ldconfig, METH_NOARGS|METH_STATIC,
00558 "ds.Ldconfig -> nds - Return /etc/ld.so.cache dependency set.\n"},
00559 #ifdef NOTYET
00560 {"Compare", (PyCFunction)rpmds_Compare, METH_VARARGS|METH_KEYWORDS,
00561 NULL},
00562 {"Problem", (PyCFunction)rpmds_Problem, METH_NOARGS,
00563 NULL},
00564 #endif
00565 {NULL, NULL}
00566 };
00567
00568
00569
00570
00571 static void
00572 rpmds_dealloc(rpmdsObject * s)
00573
00574 {
00575 if (s) {
00576 s->ds = rpmdsFree(s->ds);
00577 PyObject_Del(s);
00578 }
00579 }
00580
00581 static int
00582 rpmds_print(rpmdsObject * s, FILE * fp, int flags)
00583
00584
00585 {
00586 if (!(s && s->ds))
00587 return -1;
00588
00589 s->ds = rpmdsInit(s->ds);
00590 while (rpmdsNext(s->ds) >= 0)
00591 fprintf(fp, "%s\n", rpmdsDNEVR(s->ds));
00592 return 0;
00593 }
00594
00595 static PyObject * rpmds_getattro(PyObject * o, PyObject * n)
00596
00597 {
00598 return PyObject_GenericGetAttr(o, n);
00599 }
00600
00601 static int rpmds_setattro(PyObject * o, PyObject * n, PyObject * v)
00602
00603 {
00604 return PyObject_GenericSetAttr(o, n, v);
00605 }
00606
00607 static int
00608 rpmds_length(rpmdsObject * s)
00609
00610 {
00611 return rpmdsCount(s->ds);
00612 }
00613
00614
00615 static PyObject *
00616 rpmds_subscript(rpmdsObject * s, PyObject * key)
00617
00618 {
00619 int ix;
00620
00621 if (!PyInt_Check(key)) {
00622 PyErr_SetString(PyExc_TypeError, "integer expected");
00623 return NULL;
00624 }
00625
00626 ix = (int) PyInt_AsLong(key);
00627
00628 rpmdsSetIx(s->ds, ix-1);
00629 (void) rpmdsNext(s->ds);
00630 return Py_BuildValue("s", rpmdsDNEVR(s->ds));
00631 }
00632
00633 static PyMappingMethods rpmds_as_mapping = {
00634 (inquiry) rpmds_length,
00635 (binaryfunc) rpmds_subscript,
00636 (objobjargproc)0,
00637 };
00638
00641 static int rpmds_init(rpmdsObject * s, PyObject *args, PyObject *kwds)
00642
00643
00644 {
00645 hdrObject * ho = NULL;
00646 PyObject * to = NULL;
00647 int tagN = RPMTAG_REQUIRENAME;
00648 int flags = 0;
00649 char * kwlist[] = {"header", "tag", "flags", NULL};
00650
00651 if (_rpmds_debug < 0)
00652 fprintf(stderr, "*** rpmds_init(%p,%p,%p)\n", s, args, kwds);
00653
00654 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Oi:rpmds_init", kwlist,
00655 &hdr_Type, &ho, &to, &flags))
00656 return -1;
00657
00658 if (to != NULL) {
00659 tagN = tagNumFromPyObject(to);
00660 if (tagN == -1) {
00661 PyErr_SetString(PyExc_KeyError, "unknown header tag");
00662 return -1;
00663 }
00664 }
00665 s->ds = rpmdsNew(hdrGetHeader(ho), tagN, flags);
00666 s->active = 0;
00667
00668 return 0;
00669 }
00670
00673 static void rpmds_free( rpmdsObject * s)
00674
00675 {
00676 if (_rpmds_debug)
00677 fprintf(stderr, "%p -- ds %p\n", s, s->ds);
00678 s->ds = rpmdsFree(s->ds);
00679
00680 PyObject_Del((PyObject *)s);
00681 }
00682
00685 static PyObject * rpmds_alloc(PyTypeObject * subtype, int nitems)
00686
00687 {
00688 PyObject * s = PyType_GenericAlloc(subtype, nitems);
00689
00690 if (_rpmds_debug < 0)
00691 fprintf(stderr, "*** rpmds_alloc(%p,%d) ret %p\n", subtype, nitems, s);
00692 return s;
00693 }
00694
00697
00698 static PyObject * rpmds_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
00699
00700
00701 {
00702 rpmdsObject * s = (void *) PyObject_New(rpmdsObject, subtype);
00703
00704
00705 if (rpmds_init(s, args, kwds) < 0) {
00706 rpmds_free(s);
00707 return NULL;
00708 }
00709
00710 if (_rpmds_debug)
00711 fprintf(stderr, "%p ++ ds %p\n", s, s->ds);
00712
00713 return (PyObject *)s;
00714 }
00715
00718
00719 static char rpmds_doc[] =
00720 "";
00721
00722
00723 PyTypeObject rpmds_Type = {
00724 PyObject_HEAD_INIT(&PyType_Type)
00725 0,
00726 "rpm.ds",
00727 sizeof(rpmdsObject),
00728 0,
00729
00730 (destructor) rpmds_dealloc,
00731 (printfunc) rpmds_print,
00732 (getattrfunc)0,
00733 (setattrfunc)0,
00734 (cmpfunc) rpmds_compare,
00735 (reprfunc)0,
00736 0,
00737 0,
00738 &rpmds_as_mapping,
00739 (hashfunc)0,
00740 (ternaryfunc)0,
00741 (reprfunc)0,
00742 (getattrofunc) rpmds_getattro,
00743 (setattrofunc) rpmds_setattro,
00744 0,
00745 Py_TPFLAGS_DEFAULT |
00746 Py_TPFLAGS_HAVE_RICHCOMPARE,
00747 rpmds_doc,
00748 #if Py_TPFLAGS_HAVE_ITER
00749 0,
00750 0,
00751 (richcmpfunc) rpmds_richcompare,
00752 0,
00753 (getiterfunc) rpmds_iter,
00754 (iternextfunc) rpmds_iternext,
00755 rpmds_methods,
00756 0,
00757 0,
00758 0,
00759 0,
00760 0,
00761 0,
00762 0,
00763 (initproc) rpmds_init,
00764 (allocfunc) rpmds_alloc,
00765 (newfunc) rpmds_new,
00766 rpmds_free,
00767 0,
00768 #endif
00769 };
00770
00771
00772
00773
00774 rpmds dsFromDs(rpmdsObject * s)
00775 {
00776 return s->ds;
00777 }
00778
00779 rpmdsObject *
00780 rpmds_Wrap(rpmds ds)
00781 {
00782 rpmdsObject * s = PyObject_New(rpmdsObject, &rpmds_Type);
00783
00784 if (s == NULL)
00785 return NULL;
00786 s->ds = ds;
00787 s->active = 0;
00788 return s;
00789 }
00790
00791
00792 rpmdsObject *
00793 rpmds_Single( PyObject * s, PyObject * args, PyObject * kwds)
00794 {
00795 PyObject * to = NULL;
00796 int tagN = RPMTAG_PROVIDENAME;
00797 const char * N;
00798 const char * EVR = NULL;
00799 int Flags = 0;
00800 char * kwlist[] = {"to", "name", "evr", "flags", NULL};
00801
00802 if (!PyArg_ParseTupleAndKeywords(args, kwds, "Os|si:Single", kwlist,
00803 &to, &N, &EVR, &Flags))
00804 return NULL;
00805
00806 if (to != NULL) {
00807 tagN = tagNumFromPyObject(to);
00808 if (tagN == -1) {
00809 PyErr_SetString(PyExc_KeyError, "unknown header tag");
00810 return NULL;
00811 }
00812 }
00813 if (N != NULL) N = xstrdup(N);
00814 if (EVR != NULL) EVR = xstrdup(EVR);
00815 return rpmds_Wrap( rpmdsSingle(tagN, N, EVR, Flags) );
00816 }
00817
00818 rpmdsObject *
00819 hdr_dsFromHeader(PyObject * s, PyObject * args, PyObject * kwds)
00820 {
00821 hdrObject * ho = (hdrObject *)s;
00822 PyObject * to = NULL;
00823 rpmTag tagN = RPMTAG_REQUIRENAME;
00824 int flags = 0;
00825 char * kwlist[] = {"to", "flags", NULL};
00826
00827 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:dsFromHeader", kwlist,
00828 &to, &flags))
00829 return NULL;
00830
00831 if (to != NULL) {
00832 tagN = tagNumFromPyObject(to);
00833 if (tagN == -1) {
00834 PyErr_SetString(PyExc_KeyError, "unknown header tag");
00835 return NULL;
00836 }
00837 }
00838 return rpmds_Wrap( rpmdsNew(hdrGetHeader(ho), tagN, flags) );
00839 }
00840
00841 rpmdsObject *
00842 hdr_dsOfHeader(PyObject * s)
00843 {
00844 hdrObject * ho = (hdrObject *)s;
00845 int tagN = RPMTAG_PROVIDENAME;
00846 int Flags = RPMSENSE_EQUAL;
00847
00848 return rpmds_Wrap( rpmdsThis(hdrGetHeader(ho), tagN, Flags) );
00849 }