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

rpmts-py.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #include <rpmcli.h>
00008 #include <rpmpgp.h>
00009 #include <rpmdb.h>
00010 
00011 #include "header-py.h"
00012 #include "rpmds-py.h"   /* XXX for rpmdsNew */
00013 #include "rpmfi-py.h"   /* XXX for rpmfiNew */
00014 #include "rpmmi-py.h"
00015 #include "rpmte-py.h"
00016 
00017 #define _RPMTS_INTERNAL /* XXX for ts->rdb, ts->availablePackage */
00018 #include "rpmts-py.h"
00019 
00020 #include "debug.h"
00021 
00022 /*@unchecked@*/
00023 /*@-shadow@*/
00024 static int _rpmts_debug = 0;
00025 /*@=shadow@*/
00026 
00027 /*@access alKey @*/
00028 /*@access FD_t @*/
00029 /*@access Header @*/
00030 /*@access rpmal @*/
00031 /*@access rpmdb @*/
00032 /*@access rpmds @*/
00033 /*@access rpmts @*/
00034 /*@access rpmtsi @*/
00035 
00156 struct rpmtsCallbackType_s {
00157     PyObject * cb;
00158     PyObject * data;
00159     rpmtsObject * tso;
00160     int pythonError;
00161     PyThreadState *_save;
00162 };
00163 
00166 /*@null@*/
00167 static PyObject *
00168 rpmts_Debug(/*@unused@*/ rpmtsObject * s, PyObject * args)
00169         /*@globals _Py_NoneStruct @*/
00170         /*@modifies _Py_NoneStruct @*/
00171 {
00172     if (!PyArg_ParseTuple(args, "i:Debug", &_rpmts_debug)) return NULL;
00173 
00174 if (_rpmts_debug < 0)
00175 fprintf(stderr, "*** rpmts_Debug(%p) ts %p\n", s, s->ts);
00176 
00177     Py_INCREF(Py_None);
00178     return Py_None;
00179 }
00180 
00187 static void rpmtsAddAvailableElement(rpmts ts, Header h,
00188                 /*@exposed@*/ /*@null@*/ fnpyKey key)
00189         /*@globals rpmGlobalMacroContext @*/
00190         /*@modifies h, ts, rpmGlobalMacroContext @*/
00191 {
00192     int scareMem = 0;
00193     rpmds provides = rpmdsNew(h, RPMTAG_PROVIDENAME, scareMem);
00194     rpmfi fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem);
00195 
00196     /* XXX FIXME: return code RPMAL_NOMATCH is error */
00197     (void) rpmalAdd(&ts->availablePackages, RPMAL_NOMATCH, key,
00198                 provides, fi, rpmtsColor(ts));
00199     fi = rpmfiFree(fi);
00200     provides = rpmdsFree(provides);
00201 
00202 if (_rpmts_debug < 0)
00203 fprintf(stderr, "\tAddAvailable(%p) list %p\n", ts, ts->availablePackages);
00204 
00205 }
00206 
00209 /*@null@*/
00210 static PyObject *
00211 rpmts_AddInstall(rpmtsObject * s, PyObject * args)
00212         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
00213         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
00214 {
00215     hdrObject * h;
00216     PyObject * key;
00217     char * how = "u";   /* XXX default to upgrade element if missing */
00218     int isUpgrade = 0;
00219 
00220     if (!PyArg_ParseTuple(args, "O!O|s:AddInstall", &hdr_Type, &h, &key, &how))
00221         return NULL;
00222 
00223     {   PyObject * hObj = (PyObject *) h;
00224         if (hObj->ob_type != &hdr_Type) {
00225             PyErr_SetString(PyExc_TypeError, "bad type for header argument");
00226             return NULL;
00227         }
00228     }
00229 
00230 if (_rpmts_debug < 0 || (_rpmts_debug > 0 && *how != 'a'))
00231 fprintf(stderr, "*** rpmts_AddInstall(%p,%p,%p,%s) ts %p\n", s, h, key, how, s->ts);
00232 
00233     if (how && strcmp(how, "a") && strcmp(how, "u") && strcmp(how, "i")) {
00234         PyErr_SetString(PyExc_TypeError, "how argument must be \"u\", \"a\", or \"i\"");
00235         return NULL;
00236     } else if (how && !strcmp(how, "u"))
00237         isUpgrade = 1;
00238 
00239     if (how && !strcmp(how, "a"))
00240         rpmtsAddAvailableElement(s->ts, hdrGetHeader(h), key);
00241     else
00242         rpmtsAddInstallElement(s->ts, hdrGetHeader(h), key, isUpgrade, NULL);
00243 
00244     /* This should increment the usage count for me */
00245     if (key)
00246         PyList_Append(s->keyList, key);
00247 
00248     Py_INCREF(Py_None);
00249     return Py_None;
00250 }
00251 
00255 /*@null@*/
00256 static PyObject *
00257 rpmts_AddErase(rpmtsObject * s, PyObject * args)
00258         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
00259         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
00260 {
00261     PyObject * o;
00262     int count;
00263     rpmdbMatchIterator mi;
00264 
00265 if (_rpmts_debug)
00266 fprintf(stderr, "*** rpmts_AddErase(%p) ts %p\n", s, s->ts);
00267 
00268     if (!PyArg_ParseTuple(args, "O:AddErase", &o))
00269         return NULL;
00270 
00271     if (PyString_Check(o)) {
00272         char * name = PyString_AsString(o);
00273 
00274         mi = rpmtsInitIterator(s->ts, RPMDBI_LABEL, name, 0);
00275         count = rpmdbGetIteratorCount(mi);
00276         if (count <= 0) {
00277             mi = rpmdbFreeIterator(mi);
00278             PyErr_SetString(pyrpmError, "package not installed");
00279             return NULL;
00280         } else { /* XXX: Note that we automatically choose to remove all matches */
00281             Header h;
00282             while ((h = rpmdbNextIterator(mi)) != NULL) {
00283                 unsigned int recOffset = rpmdbGetIteratorOffset(mi);
00284                 if (recOffset)
00285                     rpmtsAddEraseElement(s->ts, h, recOffset);
00286             }
00287         }
00288         mi = rpmdbFreeIterator(mi);
00289     } else
00290     if (PyInt_Check(o)) {
00291         uint_32 instance = PyInt_AsLong(o);
00292 
00293         mi = rpmtsInitIterator(s->ts, RPMDBI_PACKAGES, &instance, sizeof(instance));
00294         if (instance == 0 || mi == NULL) {
00295             mi = rpmdbFreeIterator(mi);
00296             PyErr_SetString(pyrpmError, "package not installed");
00297             return NULL;
00298         } else {
00299             Header h;
00300             while ((h = rpmdbNextIterator(mi)) != NULL) {
00301                 uint_32 recOffset = rpmdbGetIteratorOffset(mi);
00302                 if (recOffset)
00303                     rpmtsAddEraseElement(s->ts, h, recOffset);
00304                 break;
00305             }
00306         }
00307         mi = rpmdbFreeIterator(mi);
00308     }
00309 
00310     Py_INCREF(Py_None);
00311     return Py_None;
00312 }
00313 
00316 static int
00317 rpmts_SolveCallback(rpmts ts, rpmds ds, const void * data)
00318         /*@*/
00319 {
00320     struct rpmtsCallbackType_s * cbInfo = (struct rpmtsCallbackType_s *) data;
00321     PyObject * args, * result;
00322     int res = 1;
00323 
00324 if (_rpmts_debug)
00325 fprintf(stderr, "*** rpmts_SolveCallback(%p,%p,%p) \"%s\"\n", ts, ds, data, rpmdsDNEVR(ds));
00326 
00327     if (cbInfo->tso == NULL) return res;
00328     if (cbInfo->pythonError) return res;
00329     if (cbInfo->cb == Py_None) return res;
00330 
00331     PyEval_RestoreThread(cbInfo->_save);
00332 
00333     args = Py_BuildValue("(Oissi)", cbInfo->tso,
00334                 rpmdsTagN(ds), rpmdsN(ds), rpmdsEVR(ds), rpmdsFlags(ds));
00335     result = PyEval_CallObject(cbInfo->cb, args);
00336     Py_DECREF(args);
00337 
00338     if (!result) {
00339         cbInfo->pythonError = 1;
00340     } else {
00341         if (PyInt_Check(result))
00342             res = PyInt_AsLong(result);
00343         Py_DECREF(result);
00344     }
00345 
00346     cbInfo->_save = PyEval_SaveThread();
00347 
00348     return res;
00349 }
00350 
00353 /*@null@*/
00354 static PyObject *
00355 rpmts_Check(rpmtsObject * s, PyObject * args)
00356         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
00357         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
00358 {
00359     rpmps ps;
00360     rpmProblem p;
00361     PyObject * list, * cf;
00362     struct rpmtsCallbackType_s cbInfo;
00363     int i;
00364     int xx;
00365 
00366     memset(&cbInfo, 0, sizeof(cbInfo));
00367     if (!PyArg_ParseTuple(args, "|O:Check", &cbInfo.cb))
00368         return NULL;
00369 
00370     if (cbInfo.cb != NULL) {
00371         if (!PyCallable_Check(cbInfo.cb)) {
00372             PyErr_SetString(PyExc_TypeError, "expected a callable");
00373             return NULL;
00374         }
00375         xx = rpmtsSetSolveCallback(s->ts, rpmts_SolveCallback, (void *)&cbInfo);
00376     }
00377 
00378 if (_rpmts_debug)
00379 fprintf(stderr, "*** rpmts_Check(%p) ts %p cb %p\n", s, s->ts, cbInfo.cb);
00380 
00381     cbInfo.tso = s;
00382     cbInfo.pythonError = 0;
00383     cbInfo._save = PyEval_SaveThread();
00384 
00385     /* XXX resurrect availablePackages one more time ... */
00386     rpmalMakeIndex(s->ts->availablePackages);
00387 
00388     xx = rpmtsCheck(s->ts);
00389     ps = rpmtsProblems(s->ts);
00390 
00391     if (cbInfo.cb)
00392         xx = rpmtsSetSolveCallback(s->ts, rpmtsSolve, NULL);
00393 
00394     PyEval_RestoreThread(cbInfo._save);
00395 
00396     if (ps != NULL) {
00397         list = PyList_New(0);
00398 
00399         /* XXX TODO: rpmlib >= 4.0.3 can return multiple suggested keys. */
00400         for (i = 0; i < ps->numProblems; i++) {
00401 #ifdef  DYING
00402             cf = Py_BuildValue("((sss)(ss)iOi)", conflicts[i].byName,
00403                                conflicts[i].byVersion, conflicts[i].byRelease,
00404 
00405                                conflicts[i].needsName,
00406                                conflicts[i].needsVersion,
00407 
00408                                conflicts[i].needsFlags,
00409                                conflicts[i].suggestedPkgs ?
00410                                    conflicts[i].suggestedPkgs[0] : Py_None,
00411                                conflicts[i].sense);
00412 #else
00413             char * byName, * byVersion, * byRelease, * byArch;
00414             char * needsName, * needsOP, * needsVersion;
00415             int needsFlags, sense;
00416             fnpyKey key;
00417 
00418             p = ps->probs + i;
00419 
00420             /* XXX autorelocated i386 on ia64, fix system-config-packages! */
00421             if (p->type == RPMPROB_BADRELOCATE)
00422                 continue;
00423             byName = p->pkgNEVR;
00424             if ((byArch= strrchr(byName, '.')) != NULL)
00425                 *byArch++ = '\0';
00426             if ((byRelease = strrchr(byName, '-')) != NULL)
00427                 *byRelease++ = '\0';
00428             if ((byVersion = strrchr(byName, '-')) != NULL)
00429                 *byVersion++ = '\0';
00430 
00431             key = p->key;
00432 
00433             needsName = p->altNEVR;
00434             if (needsName[1] == ' ') {
00435                 sense = (needsName[0] == 'C')
00436                         ? RPMDEP_SENSE_CONFLICTS : RPMDEP_SENSE_REQUIRES;
00437                 needsName += 2;
00438             } else
00439                 sense = RPMDEP_SENSE_REQUIRES;
00440             if ((needsVersion = strrchr(needsName, ' ')) != NULL)
00441                 *needsVersion++ = '\0';
00442 
00443             needsFlags = 0;
00444             if ((needsOP = strrchr(needsName, ' ')) != NULL) {
00445                 for (*needsOP++ = '\0'; *needsOP != '\0'; needsOP++) {
00446                     if (*needsOP == '<')        needsFlags |= RPMSENSE_LESS;
00447                     else if (*needsOP == '>')   needsFlags |= RPMSENSE_GREATER;
00448                     else if (*needsOP == '=')   needsFlags |= RPMSENSE_EQUAL;
00449                 }
00450             }
00451 
00452             cf = Py_BuildValue("((sss)(ss)iOi)", byName, byVersion, byRelease,
00453                                needsName, needsVersion, needsFlags,
00454                                (key != NULL ? key : Py_None),
00455                                sense);
00456 #endif
00457             PyList_Append(list, (PyObject *) cf);
00458             Py_DECREF(cf);
00459         }
00460 
00461         ps = rpmpsFree(ps);
00462 
00463         return list;
00464     }
00465 
00466     Py_INCREF(Py_None);
00467     return Py_None;
00468 }
00469 
00472 /*@null@*/
00473 static PyObject *
00474 rpmts_Order(rpmtsObject * s, PyObject * args)
00475         /*@globals rpmGlobalMacroContext @*/
00476         /*@modifies s, rpmGlobalMacroContext @*/
00477 {
00478     int rc;
00479 
00480 if (_rpmts_debug)
00481 fprintf(stderr, "*** rpmts_Order(%p) ts %p\n", s, s->ts);
00482 
00483     if (!PyArg_ParseTuple(args, ":Order")) return NULL;
00484 
00485     Py_BEGIN_ALLOW_THREADS
00486     rc = rpmtsOrder(s->ts);
00487     Py_END_ALLOW_THREADS
00488 
00489     return Py_BuildValue("i", rc);
00490 }
00491 
00494 /*@null@*/
00495 static PyObject *
00496 rpmts_Clean(rpmtsObject * s, PyObject * args)
00497         /*@globals _Py_NoneStruct @*/
00498         /*@modifies s, _Py_NoneStruct @*/
00499 {
00500 if (_rpmts_debug)
00501 fprintf(stderr, "*** rpmts_Clean(%p) ts %p\n", s, s->ts);
00502 
00503     if (!PyArg_ParseTuple(args, ":Clean")) return NULL;
00504 
00505     rpmtsClean(s->ts);
00506 
00507     Py_INCREF(Py_None);
00508     return Py_None;
00509 }
00510 
00513 /*@null@*/
00514 static PyObject *
00515 rpmts_IDTXload(rpmtsObject * s, PyObject * args)
00516         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
00517         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
00518 {
00519     PyObject * result = NULL;
00520     rpmTag tag = RPMTAG_INSTALLTID;
00521     IDTX idtx;
00522 
00523 if (_rpmts_debug)
00524 fprintf(stderr, "*** rpmts_IDTXload(%p) ts %p\n", s, s->ts);
00525 
00526     if (!PyArg_ParseTuple(args, ":IDTXload")) return NULL;
00527 
00528     Py_BEGIN_ALLOW_THREADS
00529     idtx = IDTXload(s->ts, tag);
00530     Py_END_ALLOW_THREADS
00531 
00532 /*@-branchstate@*/
00533     if (idtx == NULL || idtx->nidt <= 0) {
00534         Py_INCREF(Py_None);
00535         result = Py_None;
00536     } else {
00537         PyObject * tuple;
00538         PyObject * ho;
00539         IDT idt;
00540         int i;
00541 
00542         result = PyTuple_New(idtx->nidt);
00543         for (i = 0; i < idtx->nidt; i++) {
00544             idt = idtx->idt + i;
00545             ho = (PyObject *) hdr_Wrap(idt->h);
00546             tuple = Py_BuildValue("(iOi)", idt->val.u32, ho, idt->instance);
00547             PyTuple_SET_ITEM(result,  i, tuple);
00548             Py_DECREF(ho);
00549         }
00550     }
00551 /*@=branchstate@*/
00552 
00553     idtx = IDTXfree(idtx);
00554 
00555     return result;
00556 }
00557 
00560 /*@null@*/
00561 static PyObject *
00562 rpmts_IDTXglob(rpmtsObject * s, PyObject * args)
00563         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
00564         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
00565 {
00566     PyObject * result = NULL;
00567     rpmTag tag = RPMTAG_REMOVETID;
00568     const char * globstr;
00569     IDTX idtx;
00570 
00571 if (_rpmts_debug)
00572 fprintf(stderr, "*** rpmts_IDTXglob(%p) ts %p\n", s, s->ts);
00573 
00574     if (!PyArg_ParseTuple(args, ":IDTXglob")) return NULL;
00575 
00576     Py_BEGIN_ALLOW_THREADS
00577     globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
00578     idtx = IDTXglob(s->ts, globstr, tag);
00579     globstr = _free(globstr);
00580     Py_END_ALLOW_THREADS
00581 
00582 /*@-branchstate@*/
00583     if (idtx == NULL || idtx->nidt <= 0) {
00584         Py_INCREF(Py_None);
00585         result = Py_None;
00586     } else {
00587         PyObject * tuple;
00588         PyObject * ho;
00589         IDT idt;
00590         int i;
00591 
00592         result = PyTuple_New(idtx->nidt);
00593         for (i = 0; i < idtx->nidt; i++) {
00594             idt = idtx->idt + i;
00595             ho = (PyObject *) hdr_Wrap(idt->h);
00596             tuple = Py_BuildValue("(iOs)", idt->val.u32, ho, idt->key);
00597             PyTuple_SET_ITEM(result,  i, tuple);
00598             Py_DECREF(ho);
00599         }
00600     }
00601 /*@=branchstate@*/
00602 
00603     idtx = IDTXfree(idtx);
00604 
00605     return result;
00606 }
00607 
00610 /*@null@*/
00611 static PyObject *
00612 rpmts_Rollback(rpmtsObject * s, PyObject * args)
00613         /*@globals rpmGlobalMacroContext @*/
00614         /*@modifies s, rpmGlobalMacroContext @*/
00615 {
00616     struct rpmInstallArguments_s * ia = alloca(sizeof(*ia));
00617     rpmtransFlags transFlags;
00618     const char ** av = NULL;
00619     uint_32 rbtid;
00620     int rc;
00621 
00622 if (_rpmts_debug)
00623 fprintf(stderr, "*** rpmts_Rollback(%p) ts %p\n", s, s->ts);
00624 
00625     if (!PyArg_ParseTuple(args, "i:Rollback", &rbtid)) return NULL;
00626 
00627     Py_BEGIN_ALLOW_THREADS
00628     memset(ia, 0, sizeof(*ia));
00629     ia->qva_flags = (VERIFY_DIGEST|VERIFY_SIGNATURE|VERIFY_HDRCHK);
00630     ia->transFlags |= (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL);
00631     ia->transFlags |= RPMTRANS_FLAG_NOMD5;
00632     ia->installInterfaceFlags = (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL);
00633     ia->rbtid = rbtid;
00634     ia->relocations = NULL;
00635     ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
00636 
00637     transFlags = rpmtsSetFlags(s->ts, ia->transFlags);
00638     rc = rpmRollback(s->ts, ia, av);
00639     transFlags = rpmtsSetFlags(s->ts, transFlags);
00640     Py_END_ALLOW_THREADS
00641 
00642     return Py_BuildValue("i", rc);
00643 }
00644 
00647 /*@null@*/
00648 static PyObject *
00649 rpmts_OpenDB(rpmtsObject * s, PyObject * args)
00650         /*@globals rpmGlobalMacroContext @*/
00651         /*@modifies s, rpmGlobalMacroContext @*/
00652 {
00653 
00654 if (_rpmts_debug)
00655 fprintf(stderr, "*** rpmts_OpenDB(%p) ts %p\n", s, s->ts);
00656 
00657     if (!PyArg_ParseTuple(args, ":OpenDB")) return NULL;
00658 
00659     if (s->ts->dbmode == -1)
00660         s->ts->dbmode = O_RDONLY;
00661 
00662     return Py_BuildValue("i", rpmtsOpenDB(s->ts, s->ts->dbmode));
00663 }
00664 
00667 /*@null@*/
00668 static PyObject *
00669 rpmts_CloseDB(rpmtsObject * s, PyObject * args)
00670         /*@modifies s @*/
00671 {
00672     int rc;
00673 
00674 if (_rpmts_debug)
00675 fprintf(stderr, "*** rpmts_CloseDB(%p) ts %p\n", s, s->ts);
00676 
00677     if (!PyArg_ParseTuple(args, ":CloseDB")) return NULL;
00678 
00679     rc = rpmtsCloseDB(s->ts);
00680     s->ts->dbmode = -1;         /* XXX disable lazy opens */
00681 
00682     return Py_BuildValue("i", rc);
00683 }
00684 
00687 /*@null@*/
00688 static PyObject *
00689 rpmts_InitDB(rpmtsObject * s, PyObject * args)
00690         /*@globals rpmGlobalMacroContext @*/
00691         /*@modifies s, rpmGlobalMacroContext @*/
00692 {
00693     int rc;
00694 
00695 if (_rpmts_debug)
00696 fprintf(stderr, "*** rpmts_InitDB(%p) ts %p\n", s, s->ts);
00697 
00698     if (!PyArg_ParseTuple(args, ":InitDB")) return NULL;
00699 
00700     rc = rpmtsInitDB(s->ts, O_RDONLY);
00701     if (rc == 0)
00702         rc = rpmtsCloseDB(s->ts);
00703 
00704     return Py_BuildValue("i", rc);
00705 }
00706 
00709 /*@null@*/
00710 static PyObject *
00711 rpmts_RebuildDB(rpmtsObject * s, PyObject * args)
00712         /*@globals rpmGlobalMacroContext @*/
00713         /*@modifies s, rpmGlobalMacroContext @*/
00714 {
00715     int rc;
00716 
00717 if (_rpmts_debug)
00718 fprintf(stderr, "*** rpmts_RebuildDB(%p) ts %p\n", s, s->ts);
00719 
00720     if (!PyArg_ParseTuple(args, ":RebuildDB")) return NULL;
00721 
00722     Py_BEGIN_ALLOW_THREADS
00723     rc = rpmtsRebuildDB(s->ts);
00724     Py_END_ALLOW_THREADS
00725 
00726     return Py_BuildValue("i", rc);
00727 }
00728 
00731 /*@null@*/
00732 static PyObject *
00733 rpmts_VerifyDB(rpmtsObject * s, PyObject * args)
00734         /*@globals rpmGlobalMacroContext @*/
00735         /*@modifies s, rpmGlobalMacroContext @*/
00736 {
00737     int rc;
00738 
00739 if (_rpmts_debug)
00740 fprintf(stderr, "*** rpmts_VerifyDB(%p) ts %p\n", s, s->ts);
00741 
00742     if (!PyArg_ParseTuple(args, ":VerifyDB")) return NULL;
00743 
00744     Py_BEGIN_ALLOW_THREADS
00745     rc = rpmtsVerifyDB(s->ts);
00746     Py_END_ALLOW_THREADS
00747 
00748     return Py_BuildValue("i", rc);
00749 }
00750 
00753 /*@null@*/
00754 static PyObject *
00755 rpmts_HdrFromFdno(rpmtsObject * s, PyObject * args)
00756         /*@globals rpmGlobalMacroContext, fileSystem @*/
00757         /*@modifies s, rpmGlobalMacroContext, fileSystem @*/
00758 {
00759     PyObject * result = NULL;
00760     Header h;
00761     FD_t fd;
00762     int fdno;
00763     rpmRC rpmrc;
00764 
00765     if (!PyArg_ParseTuple(args, "i:HdrFromFdno", &fdno)) return NULL;
00766 
00767     fd = fdDup(fdno);
00768     rpmrc = rpmReadPackageFile(s->ts, fd, "rpmts_HdrFromFdno", &h);
00769     Fclose(fd);
00770 
00771 if (_rpmts_debug)
00772 fprintf(stderr, "*** rpmts_HdrFromFdno(%p) ts %p rc %d\n", s, s->ts, rpmrc);
00773 
00774 /*@-branchstate@*/
00775     switch (rpmrc) {
00776     case RPMRC_OK:
00777         if (h)
00778             result = Py_BuildValue("N", hdr_Wrap(h));
00779         h = headerFree(h);      /* XXX ref held by result */
00780         break;
00781 
00782     case RPMRC_NOKEY:
00783         PyErr_SetString(pyrpmError, "public key not available");
00784         break;
00785 
00786     case RPMRC_NOTTRUSTED:
00787         PyErr_SetString(pyrpmError, "public key not trusted");
00788         break;
00789 
00790     case RPMRC_NOTFOUND:
00791     case RPMRC_FAIL:
00792     default:
00793         PyErr_SetString(pyrpmError, "error reading package header");
00794         break;
00795     }
00796 /*@=branchstate@*/
00797 
00798     return result;
00799 }
00800 
00803 /*@null@*/
00804 static PyObject *
00805 rpmts_HdrCheck(rpmtsObject * s, PyObject * args)
00806         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
00807         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
00808 {
00809     PyObject * blob;
00810     PyObject * result = NULL;
00811     const char * msg = NULL;
00812     const void * uh;
00813     int uc;
00814     rpmRC rpmrc;
00815 
00816 if (_rpmts_debug)
00817 fprintf(stderr, "*** rpmts_HdrCheck(%p) ts %p\n", s, s->ts);
00818 
00819     if (!PyArg_ParseTuple(args, "O:HdrCheck", &blob)) return NULL;
00820     if (blob == Py_None) {
00821         Py_INCREF(Py_None);
00822         return Py_None;
00823     }
00824     if (!PyString_Check(blob)) {
00825         PyErr_SetString(pyrpmError, "hdrCheck takes a string of octets");
00826         return result;
00827     }
00828     uh = PyString_AsString(blob);
00829     uc = PyString_Size(blob);
00830 
00831     rpmrc = headerCheck(s->ts, uh, uc, &msg);
00832 
00833     switch (rpmrc) {
00834     case RPMRC_OK:
00835         Py_INCREF(Py_None);
00836         result = Py_None;
00837         break;
00838 
00839     case RPMRC_NOKEY:
00840         PyErr_SetString(pyrpmError, "public key not availaiable");
00841         break;
00842 
00843     case RPMRC_NOTTRUSTED:
00844         PyErr_SetString(pyrpmError, "public key not trusted");
00845         break;
00846 
00847     case RPMRC_FAIL:
00848     default:
00849         PyErr_SetString(pyrpmError, msg);
00850         break;
00851     }
00852     msg = _free(msg);
00853 
00854     return result;
00855 }
00856 
00859 /*@null@*/
00860 static PyObject *
00861 rpmts_SetVSFlags(rpmtsObject * s, PyObject * args)
00862         /*@modifies s @*/
00863 {
00864     rpmVSFlags vsflags;
00865 
00866 if (_rpmts_debug)
00867 fprintf(stderr, "*** rpmts_SetVSFlags(%p) ts %p\n", s, s->ts);
00868 
00869     if (!PyArg_ParseTuple(args, "i:SetVSFlags", &vsflags)) return NULL;
00870 
00871     /* XXX FIXME: value check on vsflags. */
00872 
00873     return Py_BuildValue("i", rpmtsSetVSFlags(s->ts, vsflags));
00874 }
00875 
00878 /*@null@*/
00879 static PyObject *
00880 rpmts_SetColor(rpmtsObject * s, PyObject * args)
00881         /*@modifies s @*/
00882 {
00883     uint_32 tscolor;
00884 
00885 if (_rpmts_debug)
00886 fprintf(stderr, "*** rpmts_SetColor(%p) ts %p\n", s, s->ts);
00887 
00888     if (!PyArg_ParseTuple(args, "i:Color", &tscolor)) return NULL;
00889 
00890     /* XXX FIXME: value check on tscolor. */
00891 
00892     return Py_BuildValue("i", rpmtsSetColor(s->ts, tscolor));
00893 }
00894 
00897 /*@null@*/
00898 static PyObject *
00899 rpmts_PgpPrtPkts(rpmtsObject * s, PyObject * args)
00900         /*@globals _Py_NoneStruct @*/
00901         /*@modifies _Py_NoneStruct @*/
00902 {
00903     PyObject * blob;
00904     unsigned char * pkt;
00905     unsigned int pktlen;
00906     int rc;
00907 
00908 if (_rpmts_debug)
00909 fprintf(stderr, "*** rpmts_PgpPrtPkts(%p) ts %p\n", s, s->ts);
00910 
00911     if (!PyArg_ParseTuple(args, "O:PgpPrtPkts", &blob)) return NULL;
00912     if (blob == Py_None) {
00913         Py_INCREF(Py_None);
00914         return Py_None;
00915     }
00916     if (!PyString_Check(blob)) {
00917         PyErr_SetString(pyrpmError, "pgpPrtPkts takes a string of octets");
00918         return NULL;
00919     }
00920     pkt = PyString_AsString(blob);
00921     pktlen = PyString_Size(blob);
00922 
00923     rc = pgpPrtPkts(pkt, pktlen, NULL, 1);
00924 
00925     return Py_BuildValue("i", rc);
00926 }
00927 
00930 /*@null@*/
00931 static PyObject *
00932 rpmts_PgpImportPubkey(rpmtsObject * s, PyObject * args)
00933         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
00934         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
00935 {
00936     PyObject * blob;
00937     unsigned char * pkt;
00938     unsigned int pktlen;
00939     int rc;
00940 
00941 if (_rpmts_debug)
00942 fprintf(stderr, "*** rpmts_PgpImportPubkey(%p) ts %p\n", s, s->ts);
00943 
00944     if (!PyArg_ParseTuple(args, "O:PgpImportPubkey", &blob)) return NULL;
00945     if (blob == Py_None) {
00946         Py_INCREF(Py_None);
00947         return Py_None;
00948     }
00949     if (!PyString_Check(blob)) {
00950         PyErr_SetString(pyrpmError, "PgpImportPubkey takes a string of octets");
00951         return NULL;
00952     }
00953     pkt = PyString_AsString(blob);
00954     pktlen = PyString_Size(blob);
00955 
00956     rc = rpmcliImportPubkey(s->ts, pkt, pktlen);
00957 
00958     return Py_BuildValue("i", rc);
00959 }
00960 
00963 /*@null@*/
00964 static PyObject *
00965 rpmts_GetKeys(rpmtsObject * s, PyObject * args)
00966         /*@globals _Py_NoneStruct @*/
00967         /*@modifies s, _Py_NoneStruct @*/
00968 {
00969     const void **data = NULL;
00970     int num, i;
00971     PyObject *tuple;
00972 
00973 if (_rpmts_debug)
00974 fprintf(stderr, "*** rpmts_GetKeys(%p) ts %p\n", s, s->ts);
00975 
00976     if (!PyArg_ParseTuple(args, ":GetKeys")) return NULL;
00977 
00978     rpmtsGetKeys(s->ts, &data, &num);
00979     if (data == NULL || num <= 0) {
00980         data = _free(data);
00981         Py_INCREF(Py_None);
00982         return Py_None;
00983     }
00984 
00985     tuple = PyTuple_New(num);
00986 
00987     for (i = 0; i < num; i++) {
00988         PyObject *obj;
00989         obj = (data[i] ? (PyObject *) data[i] : Py_None);
00990         Py_INCREF(obj);
00991         PyTuple_SetItem(tuple, i, obj);
00992     }
00993 
00994     data = _free(data);
00995 
00996     return tuple;
00997 }
00998 
01001 /*@null@*/
01002 static void *
01003 rpmtsCallback(/*@unused@*/ const void * hd, const rpmCallbackType what,
01004                          const unsigned long amount, const unsigned long total,
01005                          const void * pkgKey, rpmCallbackData data)
01006         /*@globals _Py_NoneStruct @*/
01007         /*@modifies _Py_NoneStruct @*/
01008 {
01009 /*@-castexpose@*/
01010     Header h = (Header) hd;
01011 /*@=castexpose@*/
01012     struct rpmtsCallbackType_s * cbInfo = data;
01013     PyObject * pkgObj = (PyObject *) pkgKey;
01014     PyObject * args, * result;
01015     static FD_t fd;
01016 
01017     if (cbInfo->pythonError) return NULL;
01018     if (cbInfo->cb == Py_None) return NULL;
01019 
01020     /* Synthesize a python object for callback (if necessary). */
01021     if (pkgObj == NULL) {
01022         if (h) {
01023             const char * n = NULL;
01024             (void) headerNVR(h, &n, NULL, NULL);
01025             pkgObj = Py_BuildValue("s", n);
01026         } else {
01027             pkgObj = Py_None;
01028             Py_INCREF(pkgObj);
01029         }
01030     } else
01031         Py_INCREF(pkgObj);
01032 
01033     PyEval_RestoreThread(cbInfo->_save);
01034 
01035     args = Py_BuildValue("(illOO)", what, amount, total, pkgObj, cbInfo->data);
01036     result = PyEval_CallObject(cbInfo->cb, args);
01037     Py_DECREF(args);
01038     Py_DECREF(pkgObj);
01039 
01040     if (!result) {
01041         cbInfo->pythonError = 1;
01042         cbInfo->_save = PyEval_SaveThread();
01043         return NULL;
01044     }
01045 
01046     if (what == RPMCALLBACK_INST_OPEN_FILE) {
01047         int fdno;
01048 
01049         if (!PyArg_Parse(result, "i", &fdno)) {
01050             cbInfo->pythonError = 1;
01051             cbInfo->_save = PyEval_SaveThread();
01052             return NULL;
01053         }
01054         Py_DECREF(result);
01055         cbInfo->_save = PyEval_SaveThread();
01056 
01057         fd = fdDup(fdno);
01058 if (_rpmts_debug)
01059 fprintf(stderr, "\t%p = fdDup(%d)\n", fd, fdno);
01060 
01061         return fd;
01062     } else
01063     if (what == RPMCALLBACK_INST_CLOSE_FILE) {
01064 if (_rpmts_debug)
01065 fprintf(stderr, "\tFclose(%p)\n", fd);
01066         Fclose (fd);
01067     } else {
01068 if (_rpmts_debug)
01069 fprintf(stderr, "\t%ld:%ld key %p\n", amount, total, pkgKey);
01070     }
01071 
01072     Py_DECREF(result);
01073     cbInfo->_save = PyEval_SaveThread();
01074 
01075     return NULL;
01076 }
01077 
01080 static PyObject * rpmts_SetFlags(rpmtsObject * s, PyObject * args)
01081         /*@modifies s @*/
01082 {
01083     rpmtransFlags transFlags = 0;
01084 
01085     if (!PyArg_ParseTuple(args, "i:SetFlags", &transFlags))
01086         return NULL;
01087 
01088 if (_rpmts_debug)
01089 fprintf(stderr, "*** rpmts_SetFlags(%p) ts %p transFlags %x\n", s, s->ts, transFlags);
01090 
01091     return Py_BuildValue("i", rpmtsSetFlags(s->ts, transFlags));
01092 }
01093 
01096 static PyObject * rpmts_SetProbFilter(rpmtsObject * s, PyObject * args)
01097         /*@modifies s @*/
01098 {
01099     rpmprobFilterFlags ignoreSet = 0;
01100     rpmprobFilterFlags oignoreSet;
01101 
01102     if (!PyArg_ParseTuple(args, "i:ProbFilter", &ignoreSet))
01103         return NULL;
01104 
01105 if (_rpmts_debug)
01106 fprintf(stderr, "*** rpmts_SetProbFilter(%p) ts %p ignoreSet %x\n", s, s->ts, ignoreSet);
01107 
01108     oignoreSet = s->ignoreSet;
01109     s->ignoreSet = ignoreSet;
01110 
01111     return Py_BuildValue("i", oignoreSet);
01112 }
01113 
01116 static PyObject * rpmts_Run(rpmtsObject * s, PyObject * args)
01117         /*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
01118         /*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
01119 {
01120     int rc, i;
01121     PyObject * list;
01122     rpmps ps;
01123     struct rpmtsCallbackType_s cbInfo;
01124 
01125     if (!PyArg_ParseTuple(args, "OO:Run", &cbInfo.cb, &cbInfo.data))
01126         return NULL;
01127 
01128     cbInfo.tso = s;
01129     cbInfo.pythonError = 0;
01130     cbInfo._save = PyEval_SaveThread();
01131 
01132     if (cbInfo.cb != NULL) {
01133         if (!PyCallable_Check(cbInfo.cb)) {
01134             PyErr_SetString(PyExc_TypeError, "expected a callable");
01135             return NULL;
01136         }
01137         (void) rpmtsSetNotifyCallback(s->ts, rpmtsCallback, (void *) &cbInfo);
01138     }
01139 
01140     /* Initialize security context patterns (if not already done). */
01141     if (!(s->ts->transFlags & RPMTRANS_FLAG_NOCONTEXTS) && rpmtsSELinuxEnabled(s->ts)) {
01142         rpmsx sx = rpmtsREContext(s->ts);
01143         if (sx == NULL) {
01144             const char *fn = rpmGetPath("%{?_install_file_context_path}", NULL);
01145             if (fn != NULL && *fn != '\0') {
01146                 sx = rpmsxNew(fn);
01147                 (void) rpmtsSetREContext(s->ts, sx);
01148             }
01149             fn = _free(fn);
01150         }
01151         sx = rpmsxFree(sx);
01152     } 
01153 
01154 
01155 if (_rpmts_debug)
01156 fprintf(stderr, "*** rpmts_Run(%p) ts %p ignore %x\n", s, s->ts, s->ignoreSet);
01157 
01158     rc = rpmtsRun(s->ts, NULL, s->ignoreSet);
01159     ps = rpmtsProblems(s->ts);
01160 
01161     if (cbInfo.cb)
01162         (void) rpmtsSetNotifyCallback(s->ts, NULL, NULL);
01163 
01164     PyEval_RestoreThread(cbInfo._save);
01165 
01166     if (cbInfo.pythonError) {
01167         ps = rpmpsFree(ps);
01168         return NULL;
01169     }
01170 
01171     if (rc < 0) {
01172         list = PyList_New(0);
01173         return list;
01174     } else if (!rc) {
01175         Py_INCREF(Py_None);
01176         return Py_None;
01177     }
01178 
01179     list = PyList_New(0);
01180     for (i = 0; i < ps->numProblems; i++) {
01181         rpmProblem p = ps->probs + i;
01182         PyObject * prob = Py_BuildValue("s(isN)", rpmProblemString(p),
01183                              p->type,
01184                              p->str1,
01185                              PyLong_FromLongLong(p->ulong1));
01186         PyList_Append(list, prob);
01187         Py_DECREF(prob);
01188     }
01189 
01190     ps = rpmpsFree(ps);
01191 
01192     return list;
01193 }
01194 
01195 #if Py_TPFLAGS_HAVE_ITER
01196 static PyObject *
01197 rpmts_iter(rpmtsObject * s)
01198         /*@*/
01199 {
01200 if (_rpmts_debug)
01201 fprintf(stderr, "*** rpmts_iter(%p) ts %p\n", s, s->ts);
01202 
01203     Py_INCREF(s);
01204     return (PyObject *)s;
01205 }
01206 #endif
01207 
01211 /*@null@*/
01212 static PyObject *
01213 rpmts_iternext(rpmtsObject * s)
01214         /*@modifies s @*/
01215 {
01216     PyObject * result = NULL;
01217     rpmte te;
01218 
01219 if (_rpmts_debug)
01220 fprintf(stderr, "*** rpmts_iternext(%p) ts %p tsi %p %d\n", s, s->ts, s->tsi, s->tsiFilter);
01221 
01222     /* Reset iterator on 1st entry. */
01223     if (s->tsi == NULL) {
01224         s->tsi = rpmtsiInit(s->ts);
01225         if (s->tsi == NULL)
01226             return NULL;
01227         s->tsiFilter = 0;
01228     }
01229 
01230     te = rpmtsiNext(s->tsi, s->tsiFilter);
01231 /*@-branchstate@*/
01232     if (te != NULL) {
01233         result = (PyObject *) rpmte_Wrap(te);
01234     } else {
01235         s->tsi = rpmtsiFree(s->tsi);
01236         s->tsiFilter = 0;
01237     }
01238 /*@=branchstate@*/
01239 
01240     return result;
01241 }
01242 
01246 static PyObject *
01247 rpmts_Next(rpmtsObject * s)
01248         /*@globals _Py_NoneStruct @*/
01249         /*@modifies s, _Py_NoneStruct @*/
01250 {
01251     PyObject * result;
01252 
01253 if (_rpmts_debug)
01254 fprintf(stderr, "*** rpmts_Next(%p) ts %p\n", s, s->ts);
01255 
01256     result = rpmts_iternext(s);
01257 
01258     if (result == NULL) {
01259         Py_INCREF(Py_None);
01260         return Py_None;
01261     }
01262 
01263     return result;
01264 }
01265 
01268 /*@null@*/
01269 static rpmmiObject *
01270 rpmts_Match(rpmtsObject * s, PyObject * args)
01271         /*@globals rpmGlobalMacroContext @*/
01272         /*@modifies s, rpmGlobalMacroContext @*/
01273 {
01274     PyObject *TagN = NULL;
01275     PyObject *Key = NULL;
01276     char *key = NULL;
01277     long lkey = 0;
01278     int len = 0;
01279     int tag = RPMDBI_PACKAGES;
01280 
01281 if (_rpmts_debug)
01282 fprintf(stderr, "*** rpmts_Match(%p) ts %p\n", s, s->ts);
01283 
01284     if (!PyArg_ParseTuple(args, "|OO", &TagN, &Key))
01285         return NULL;
01286 
01287     if (TagN && (tag = tagNumFromPyObject (TagN)) == -1) {
01288         PyErr_SetString(PyExc_TypeError, "unknown tag type");
01289         return NULL;
01290 
01291     }
01292 
01293     if (Key) {
01294         if (PyString_Check(Key)) {
01295             key = PyString_AsString(Key);
01296             len = PyString_Size(Key);
01297         } else if (PyInt_Check(Key)) {
01298             lkey = PyInt_AsLong(Key);
01299             key = (char *)&lkey;
01300             len = sizeof(lkey);
01301         } else {
01302             PyErr_SetString(PyExc_TypeError, "unknown key type");
01303             return NULL;
01304         }
01305     }
01306 
01307     /* XXX If not already opened, open the database O_RDONLY now. */
01308     /* XXX FIXME: lazy default rdonly open also done by rpmtsInitIterator(). */
01309     if (s->ts->rdb == NULL) {
01310         int rc = rpmtsOpenDB(s->ts, O_RDONLY);
01311         if (rc || s->ts->rdb == NULL) {
01312             PyErr_SetString(PyExc_TypeError, "rpmdb open failed");
01313             return NULL;
01314         }
01315     }
01316 
01317     return rpmmi_Wrap( rpmtsInitIterator(s->ts, tag, key, len) );
01318 }
01319 
01322 /*@-fullinitblock@*/
01323 /*@unchecked@*/ /*@observer@*/
01324 static struct PyMethodDef rpmts_methods[] = {
01325  {"Debug",      (PyCFunction)rpmts_Debug,       METH_VARARGS,
01326         NULL},
01327 
01328  {"addInstall", (PyCFunction) rpmts_AddInstall, METH_VARARGS,
01329         NULL },
01330  {"addErase",   (PyCFunction) rpmts_AddErase,   METH_VARARGS,
01331         NULL },
01332  {"check",      (PyCFunction) rpmts_Check,      METH_VARARGS,
01333         NULL },
01334  {"order",      (PyCFunction) rpmts_Order,      METH_VARARGS,
01335         NULL },
01336  {"setFlags",   (PyCFunction) rpmts_SetFlags,   METH_VARARGS,
01337 "ts.setFlags(transFlags) -> previous transFlags\n\
01338 - Set control bit(s) for executing ts.run().\n\
01339   Note: This method replaces the 1st argument to the old ts.run()\n" },
01340  {"setProbFilter",      (PyCFunction) rpmts_SetProbFilter,      METH_VARARGS,
01341 "ts.setProbFilter(ignoreSet) -> previous ignoreSet\n\
01342 - Set control bit(s) for ignoring problems found by ts.run().\n\
01343   Note: This method replaces the 2nd argument to the old ts.run()\n" },
01344  {"run",        (PyCFunction) rpmts_Run,        METH_VARARGS,
01345 "ts.run(callback, data) -> (problems)\n\
01346 - Run a transaction set, returning list of problems found.\n\
01347   Note: The callback may not be None.\n" },
01348  {"clean",      (PyCFunction) rpmts_Clean,      METH_VARARGS,
01349         NULL },
01350  {"IDTXload",   (PyCFunction) rpmts_IDTXload,   METH_VARARGS,
01351 "ts.IDTXload() -> ((tid,hdr,instance)+)\n\
01352 - Return list of installed packages reverse sorted by transaction id.\n" },
01353  {"IDTXglob",   (PyCFunction) rpmts_IDTXglob,   METH_VARARGS,
01354 "ts.IDTXglob() -> ((tid,hdr,instance)+)\n\
01355 - Return list of removed packages reverse sorted by transaction id.\n" },
01356  {"rollback",   (PyCFunction) rpmts_Rollback,   METH_VARARGS,
01357         NULL },
01358  {"openDB",     (PyCFunction) rpmts_OpenDB,     METH_VARARGS,
01359 "ts.openDB() -> None\n\
01360 - Open the default transaction rpmdb.\n\
01361   Note: The transaction rpmdb is lazily opened, so ts.openDB() is seldom needed.\n" },
01362  {"closeDB",    (PyCFunction) rpmts_CloseDB,    METH_VARARGS,
01363 "ts.closeDB() -> None\n\
01364 - Close the default transaction rpmdb.\n\
01365   Note: ts.closeDB() disables lazy opens, and should hardly ever be used.\n" },
01366  {"initDB",     (PyCFunction) rpmts_InitDB,     METH_VARARGS,
01367 "ts.initDB() -> None\n\
01368 - Initialize the default transaction rpmdb.\n\
01369  Note: ts.initDB() is seldom needed anymore.\n" },
01370  {"rebuildDB",  (PyCFunction) rpmts_RebuildDB,  METH_VARARGS,
01371 "ts.rebuildDB() -> None\n\
01372 - Rebuild the default transaction rpmdb.\n" },
01373  {"verifyDB",   (PyCFunction) rpmts_VerifyDB,   METH_VARARGS,
01374 "ts.verifyDB() -> None\n\
01375 - Verify the default transaction rpmdb.\n" },
01376  {"hdrFromFdno",(PyCFunction) rpmts_HdrFromFdno,METH_VARARGS,
01377 "ts.hdrFromFdno(fdno) -> hdr\n\
01378 - Read a package header from a file descriptor.\n" },
01379  {"hdrCheck",   (PyCFunction) rpmts_HdrCheck,   METH_VARARGS,
01380         NULL },
01381  {"setVSFlags",(PyCFunction) rpmts_SetVSFlags,  METH_VARARGS,
01382 "ts.setVSFlags(vsflags) -> ovsflags\n\
01383 - Set signature verification flags. Values for vsflags are:\n\
01384     rpm.RPMVSF_NOHDRCHK      if set, don't check rpmdb headers\n\
01385     rpm.RPMVSF_NEEDPAYLOAD   if not set, check header+payload (if possible)\n\
01386     rpm.RPMVSF_NOSHA1HEADER  if set, don't check header SHA1 digest\n\
01387     rpm.RPMVSF_NODSAHEADER   if set, don't check header DSA signature\n\
01388     rpm.RPMVSF_NOMD5         if set, don't check header+payload MD5 digest\n\
01389     rpm.RPMVSF_NODSA         if set, don't check header+payload DSA signature\n\
01390     rpm.RPMVSF_NORSA         if set, don't check header+payload RSA signature\n\
01391     rpm._RPMVSF_NODIGESTS    if set, don't check digest(s)\n\
01392     rpm._RPMVSF_NOSIGNATURES if set, don't check signature(s)\n" },
01393  {"setColor",(PyCFunction) rpmts_SetColor,      METH_VARARGS,
01394         NULL },
01395  {"pgpPrtPkts", (PyCFunction) rpmts_PgpPrtPkts, METH_VARARGS,
01396         NULL },
01397  {"pgpImportPubkey",    (PyCFunction) rpmts_PgpImportPubkey,    METH_VARARGS,
01398         NULL },
01399  {"getKeys",    (PyCFunction) rpmts_GetKeys,    METH_VARARGS,
01400         NULL },
01401  {"dbMatch",    (PyCFunction) rpmts_Match,      METH_VARARGS,
01402 "ts.dbMatch([TagN, [key, [len]]]) -> mi\n\
01403 - Create a match iterator for the default transaction rpmdb.\n" },
01404  {"next",               (PyCFunction)rpmts_Next,        METH_VARARGS,
01405 "ts.next() -> te\n\
01406 - Retrieve next transaction set element.\n" },
01407     {NULL,              NULL}           /* sentinel */
01408 };
01409 /*@=fullinitblock@*/
01410 
01413 static void rpmts_dealloc(/*@only@*/ rpmtsObject * s)
01414         /*@modifies *s @*/
01415 {
01416 
01417 if (_rpmts_debug)
01418 fprintf(stderr, "%p -- ts %p db %p\n", s, s->ts, s->ts->rdb);
01419     s->ts = rpmtsFree(s->ts);
01420 
01421     if (s->scriptFd) Fclose(s->scriptFd);
01422     /* this will free the keyList, and decrement the ref count of all
01423        the items on the list as well :-) */
01424     Py_DECREF(s->keyList);
01425     PyObject_Del((PyObject *)s);
01426 }
01427 
01428 static PyObject * rpmts_getattro(PyObject * o, PyObject * n)
01429         /*@*/
01430 {
01431     return PyObject_GenericGetAttr(o, n);
01432 }
01433 
01436 static int rpmts_setattro(PyObject * o, PyObject * n, PyObject * v)
01437         /*@*/
01438 {
01439     rpmtsObject *s = (rpmtsObject *)o;
01440     char * name = PyString_AsString(n);
01441     int fdno;
01442 
01443     if (!strcmp(name, "scriptFd")) {
01444         if (!PyArg_Parse(v, "i", &fdno)) return 0;
01445         if (fdno < 0) {
01446             PyErr_SetString(PyExc_TypeError, "bad file descriptor");
01447             return -1;
01448         } else {
01449             s->scriptFd = fdDup(fdno);
01450             rpmtsSetScriptFd(s->ts, s->scriptFd);
01451         }
01452     } else {
01453         PyErr_SetString(PyExc_AttributeError, name);
01454         return -1;
01455     }
01456 
01457     return 0;
01458 }
01459 
01462 static int rpmts_init(rpmtsObject * s, PyObject *args, PyObject *kwds)
01463         /*@globals rpmGlobalMacroContext @*/
01464         /*@modifies s, rpmGlobalMacroContext @*/
01465 {
01466     char * rootDir = "/";
01467     int vsflags = rpmExpandNumeric("%{?_vsflags_up2date}");
01468 
01469 if (_rpmts_debug < 0)
01470 fprintf(stderr, "*** rpmts_init(%p,%p,%p)\n", s, args, kwds);
01471 
01472     if (!PyArg_ParseTuple(args, "|si:rpmts_init", &rootDir, &vsflags))
01473         return -1;
01474 
01475     s->ts = rpmtsCreate();
01476     (void) rpmtsSetRootDir(s->ts, rootDir);
01477     (void) rpmtsSetVSFlags(s->ts, vsflags);
01478     s->keyList = PyList_New(0);
01479     s->scriptFd = NULL;
01480     s->tsi = NULL;
01481     s->tsiFilter = 0;
01482 
01483     return 0;
01484 }
01485 
01488 static void rpmts_free(/*@only@*/ rpmtsObject * s)
01489         /*@modifies s @*/
01490 {
01491 if (_rpmts_debug)
01492 fprintf(stderr, "%p -- ts %p db %p\n", s, s->ts, s->ts->rdb);
01493     s->ts = rpmtsFree(s->ts);
01494 
01495     if (s->scriptFd)
01496         Fclose(s->scriptFd);
01497 
01498     /* this will free the keyList, and decrement the ref count of all
01499        the items on the list as well :-) */
01500     Py_DECREF(s->keyList);
01501 
01502     PyObject_Del((PyObject *)s);
01503 }
01504 
01507 static PyObject * rpmts_alloc(PyTypeObject * subtype, int nitems)
01508         /*@*/
01509 {
01510     PyObject * s = PyType_GenericAlloc(subtype, nitems);
01511 
01512 if (_rpmts_debug < 0)
01513 fprintf(stderr, "*** rpmts_alloc(%p,%d) ret %p\n", subtype, nitems, s);
01514     return s;
01515 }
01516 
01519 static PyObject * rpmts_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
01520         /*@globals rpmGlobalMacroContext @*/
01521         /*@modifies rpmGlobalMacroContext @*/
01522 {
01523     rpmtsObject * s = (void *) PyObject_New(rpmtsObject, subtype);
01524 
01525     /* Perform additional initialization. */
01526     if (rpmts_init(s, args, kwds) < 0) {
01527         rpmts_free(s);
01528         return NULL;
01529     }
01530 
01531 if (_rpmts_debug)
01532 fprintf(stderr, "%p ++ ts %p db %p\n", s, s->ts, s->ts->rdb);
01533 
01534     return (PyObject *)s;
01535 }
01536 
01539 /*@unchecked@*/ /*@observer@*/
01540 static char rpmts_doc[] =
01541 "";
01542 
01545 /*@-fullinitblock@*/
01546 PyTypeObject rpmts_Type = {
01547         PyObject_HEAD_INIT(&PyType_Type)
01548         0,                              /* ob_size */
01549         "rpm.ts",                       /* tp_name */
01550         sizeof(rpmtsObject),            /* tp_size */
01551         0,                              /* tp_itemsize */
01552         (destructor) rpmts_dealloc,     /* tp_dealloc */
01553         0,                              /* tp_print */
01554         (getattrfunc)0,                 /* tp_getattr */
01555         (setattrfunc)0,                 /* tp_setattr */
01556         0,                              /* tp_compare */
01557         0,                              /* tp_repr */
01558         0,                              /* tp_as_number */
01559         0,                              /* tp_as_sequence */
01560         0,                              /* tp_as_mapping */
01561         0,                              /* tp_hash */
01562         0,                              /* tp_call */
01563         0,                              /* tp_str */
01564         (getattrofunc) rpmts_getattro,  /* tp_getattro */
01565         (setattrofunc) rpmts_setattro,  /* tp_setattro */
01566         0,                              /* tp_as_buffer */
01567         Py_TPFLAGS_DEFAULT,             /* tp_flags */
01568         rpmts_doc,                      /* tp_doc */
01569 #if Py_TPFLAGS_HAVE_ITER
01570         0,                              /* tp_traverse */
01571         0,                              /* tp_clear */
01572         0,                              /* tp_richcompare */
01573         0,                              /* tp_weaklistoffset */
01574         (getiterfunc) rpmts_iter,       /* tp_iter */
01575         (iternextfunc) rpmts_iternext,  /* tp_iternext */
01576         rpmts_methods,                  /* tp_methods */
01577         0,                              /* tp_members */
01578         0,                              /* tp_getset */
01579         0,                              /* tp_base */
01580         0,                              /* tp_dict */
01581         0,                              /* tp_descr_get */
01582         0,                              /* tp_descr_set */
01583         0,                              /* tp_dictoffset */
01584         (initproc) rpmts_init,          /* tp_init */
01585         (allocfunc) rpmts_alloc,        /* tp_alloc */
01586         (newfunc) rpmts_new,            /* tp_new */
01587         rpmts_free,                     /* tp_free */
01588         0,                              /* tp_is_gc */
01589 #endif
01590 };
01591 /*@=fullinitblock@*/
01592 
01595 rpmtsObject *
01596 rpmts_Create(/*@unused@*/ PyObject * self, PyObject * args)
01597 {
01598     rpmtsObject * o;
01599     char * rootDir = "/";
01600     int vsflags = rpmExpandNumeric("%{?_vsflags_up2date}");
01601 
01602     if (!PyArg_ParseTuple(args, "|si:Create", &rootDir, &vsflags))
01603         return NULL;
01604 
01605     o = (void *) PyObject_New(rpmtsObject, &rpmts_Type);
01606 
01607     o->ts = rpmtsCreate();
01608     (void) rpmtsSetRootDir(o->ts, rootDir);
01609     (void) rpmtsSetVSFlags(o->ts, vsflags);
01610 
01611     o->keyList = PyList_New(0);
01612     o->scriptFd = NULL;
01613     o->tsi = NULL;
01614     o->tsiFilter = 0;
01615 
01616 if (_rpmts_debug)
01617 fprintf(stderr, "%p ++ ts %p db %p\n", o, o->ts, o->ts->rdb);
01618     return o;
01619 }

Generated on Mon Oct 3 16:57:49 2011 for rpm by  doxygen 1.3.9.1