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