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