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