1 #include "rpmsystem-py.h"
3 #include <rpm/rpmlib.h> /* rpmReadPackageFile, headerCheck */
4 #include <rpm/rpmtag.h>
5 #include <rpm/rpmpgp.h>
7 #include <rpm/rpmbuild.h>
10 #include "rpmds-py.h" /* XXX for rpmdsNew */
12 #include "rpmfi-py.h" /* XXX for rpmfiNew */
25 * \brief A python rpm.ts object represents an RPM transaction set.
27 * The transaction set is the workhorse of RPM. It performs the
28 * installation and upgrade of packages. The rpm.ts object is
29 * instantiated by the TransactionSet function in the rpm module.
31 * The TransactionSet function takes two optional arguments. The first
32 * argument is the root path. The second is the verify signature disable flags,
33 * a set of the following bits:
35 * - rpm.RPMVSF_NOHDRCHK if set, don't check rpmdb headers
36 * - rpm.RPMVSF_NEEDPAYLOAD if not set, check header+payload (if possible)
37 * - rpm.RPMVSF_NOSHA1HEADER if set, don't check header SHA1 digest
38 * - rpm.RPMVSF_NODSAHEADER if set, don't check header DSA signature
39 * - rpm.RPMVSF_NOMD5 if set, don't check header+payload MD5 digest
40 * - rpm.RPMVSF_NODSA if set, don't check header+payload DSA signature
41 * - rpm.RPMVSF_NORSA if set, don't check header+payload RSA signature
43 * For convenience, there are the following masks:
44 * - rpm._RPMVSF_NODIGESTS if set, don't check digest(s).
45 * - rpm._RPMVSF_NOSIGNATURES if set, don't check signature(s).
47 * A rpm.ts object has the following methods:
49 * - addInstall(hdr,data,mode) Add an install element to a transaction set.
50 * @param hdr the header to be added
51 * @param data user data that will be passed to the transaction callback
52 * during transaction execution
53 * @param mode optional argument that specifies if this package should
54 * be installed ('i'), upgraded ('u').
56 * - addErase(name) Add an erase element to a transaction set.
57 * @param name the package name to be erased
59 * - check() Perform a dependency check on the transaction set. After
60 * headers have been added to a transaction set, a dependency
61 * check can be performed to make sure that all package
62 * dependencies are satisfied.
63 * @return None If there are no unresolved dependencies
64 * Otherwise a list of complex tuples is returned, one tuple per
65 * unresolved dependency, with
66 * The format of the dependency tuple is:
67 * ((packageName, packageVersion, packageRelease),
68 * (reqName, reqVersion),
72 * packageName, packageVersion, packageRelease are the name,
73 * version, and release of the package that has the unresolved
74 * dependency or conflict.
75 * The reqName and reqVersion are the name and version of the
76 * requirement or conflict.
77 * The needsFlags is a bitfield that describes the versioned
78 * nature of a requirement or conflict. The constants
79 * rpm.RPMSENSE_LESS, rpm.RPMSENSE_GREATER, and
80 * rpm.RPMSENSE_EQUAL can be logical ANDed with the needsFlags
81 * to get versioned dependency information.
82 * suggestedPackage is a tuple if the dependency check was aware
83 * of a package that solves this dependency problem when the
84 * dependency check was run. Packages that are added to the
85 * transaction set as "available" are examined during the
86 * dependency check as possible dependency solvers. The tuple
87 * contains two values, (header, suggestedName). These are set to
88 * the header of the suggested package and its name, respectively.
89 * If there is no known package to solve the dependency problem,
90 * suggestedPackage is None.
91 * The constants rpm.RPMDEP_SENSE_CONFLICTS and
92 * rpm.RPMDEP_SENSE_REQUIRES are set to show a dependency as a
93 * requirement or a conflict.
95 * - ts.order() Do a topological sort of added element relations.
98 * - ts.setFlags(transFlags) Set transaction set flags.
99 * @param transFlags - bit(s) to controll transaction operations. The
100 * following values can be logically OR'ed together:
101 * - rpm.RPMTRANS_FLAG_TEST - test mode, do not modify the RPM
102 * database, change any files, or run any package scripts
103 * - rpm.RPMTRANS_FLAG_BUILD_PROBS - only build a list of
104 * problems encountered when attempting to run this transaction
106 * - rpm.RPMTRANS_FLAG_NOSCRIPTS - do not execute package scripts
107 * - rpm.RPMTRANS_FLAG_JUSTDB - only make changes to the rpm
108 * database, do not modify files.
109 * - rpm.RPMTRANS_FLAG_NOTRIGGERS - do not run trigger scripts
110 * - rpm.RPMTRANS_FLAG_NODOCS - do not install files marked as %doc
111 * - rpm.RPMTRANS_FLAG_ALLFILES - create all files, even if a
112 * file is marked %config(missingok) and an upgrade is
114 * - rpm.RPMTRANS_FLAG_KEEPOBSOLETE - do not remove obsoleted
116 * @return previous transFlags
118 * - ts.setProbFilter(ignoreSet) Set transaction set problem filter.
119 * @param problemSetFilter - control bit(s) to ignore classes of problems,
120 * a logical or of one or more of the following bit(s):
121 * - rpm.RPMPROB_FILTER_IGNOREOS -
122 * - rpm.RPMPROB_FILTER_IGNOREARCH -
123 * - rpm.RPMPROB_FILTER_REPLACEPKG -
124 * - rpm.RPMPROB_FILTER_FORCERELOCATE -
125 * - rpm.RPMPROB_FILTER_REPLACENEWFILES -
126 * - rpm.RPMPROB_FILTER_REPLACEOLDFILES -
127 * - rpm.RPMPROB_FILTER_OLDPACKAGE -
128 * - rpm.RPMPROB_FILTER_DISKSPACE -
129 * @return previous ignoreSet
131 * - ts.run(callback,data) Attempt to execute a transaction set.
132 * After the transaction set has been populated with install/upgrade or
133 * erase actions, the transaction set can be executed by invoking
134 * the ts.run() method.
137 struct rpmtsObject_s {
139 PyObject *md_dict; /*!< to look like PyModuleObject */
141 PyObject * keyList; /* keeps reference counts correct */
144 rpmprobFilterFlags ignoreSet;
147 struct rpmtsCallbackType_s {
151 PyThreadState *_save;
155 static void die(PyObject *cb)
160 if (PyErr_Occurred()) {
163 if ((r = PyObject_Repr(cb)) != NULL) {
164 pyfn = PyString_AsString(r);
166 fprintf(stderr, _("error: python callback %s failed, aborting!\n"),
167 pyfn ? pyfn : "???");
168 rpmdbCheckTerminate(1);
173 rpmts_AddInstall(rpmtsObject * s, PyObject * args, PyObject * kwds)
177 char * how = "u"; /* XXX default to upgrade element if missing */
179 char * kwlist[] = {"header", "key", "how", NULL};
182 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O|s:AddInstall", kwlist,
183 hdrFromPyObject, &h, &key, &how))
186 if (how && !rstreq(how, "u") && !rstreq(how, "i")) {
187 PyErr_SetString(PyExc_TypeError, "how argument must be \"u\" or \"i\"");
189 } else if (how && rstreq(how, "u"))
192 rc = rpmtsAddInstallElement(s->ts, h, key, isUpgrade, NULL);
194 PyErr_SetString(pyrpmError, "adding package to transaction failed");
199 /* This should increment the usage count for me */
201 PyList_Append(s->keyList, key);
206 /* TODO Permit finer control (i.e. not just --allmatches) of deleted elments.*/
208 rpmts_AddErase(rpmtsObject * s, PyObject * args, PyObject * kwds)
212 rpmdbMatchIterator mi = NULL;
214 char * kwlist[] = {"name", NULL};
216 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:AddErase", kwlist, &o))
219 if (PyString_Check(o)) {
220 char * name = PyString_AsString(o);
221 mi = rpmtsInitIterator(s->ts, RPMDBI_LABEL, name, 0);
222 } else if (PyInt_Check(o)) {
223 uint32_t recno = PyInt_AsLong(o);
224 mi = rpmtsInitIterator(s->ts, RPMDBI_PACKAGES, &recno, sizeof(recno));
226 PyErr_SetString(PyExc_TypeError, "string or integer expected");
230 while ((h = rpmdbNextIterator(mi)) != NULL) {
232 rpmtsAddEraseElement(s->ts, h, -1);
234 rpmdbFreeIterator(mi);
239 PyErr_SetString(pyrpmError, "package not installed");
245 rpmts_SolveCallback(rpmts ts, rpmds ds, const void * data)
247 struct rpmtsCallbackType_s * cbInfo = (struct rpmtsCallbackType_s *) data;
248 PyObject * args, * result;
251 if (cbInfo->tso == NULL) return res;
252 if (cbInfo->cb == Py_None) return res;
254 PyEval_RestoreThread(cbInfo->_save);
256 args = Py_BuildValue("(Oissi)", cbInfo->tso,
257 rpmdsTagN(ds), rpmdsN(ds), rpmdsEVR(ds), rpmdsFlags(ds));
258 result = PyEval_CallObject(cbInfo->cb, args);
264 if (PyInt_Check(result))
265 res = PyInt_AsLong(result);
269 cbInfo->_save = PyEval_SaveThread();
275 rpmts_Check(rpmtsObject * s, PyObject * args, PyObject * kwds)
279 PyObject * list, * cf;
280 struct rpmtsCallbackType_s cbInfo;
282 char * kwlist[] = {"callback", NULL};
284 memset(&cbInfo, 0, sizeof(cbInfo));
285 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:Check", kwlist,
289 if (cbInfo.cb != NULL) {
290 if (!PyCallable_Check(cbInfo.cb)) {
291 PyErr_SetString(PyExc_TypeError, "expected a callable");
294 xx = rpmtsSetSolveCallback(s->ts, rpmts_SolveCallback, (void *)&cbInfo);
298 cbInfo._save = PyEval_SaveThread();
300 xx = rpmtsCheck(s->ts);
301 ps = rpmtsProblems(s->ts);
303 PyEval_RestoreThread(cbInfo._save);
306 list = PyList_New(0);
307 rpmpsi psi = rpmpsInitIterator(ps);
309 /* XXX TODO: rpmlib >= 4.0.3 can return multiple suggested keys. */
310 while (rpmpsNextIterator(psi) >= 0) {
311 char * altNEVR, * needsName;
312 char * byName, * byVersion, * byRelease, *byArch;
313 char * needsOP, * needsVersion;
314 rpmsenseFlags needsFlags, sense;
317 p = rpmpsGetProblem(psi);
319 byName = xstrdup(rpmProblemGetPkgNEVR(p));
320 if ((byArch= strrchr(byName, '.')) != NULL)
322 if ((byRelease = strrchr(byName, '-')) != NULL)
324 if ((byVersion = strrchr(byName, '-')) != NULL)
327 key = rpmProblemGetKey(p);
329 altNEVR = needsName = xstrdup(rpmProblemGetAltNEVR(p));
330 if (needsName[1] == ' ') {
331 sense = (needsName[0] == 'C')
332 ? RPMDEP_SENSE_CONFLICTS : RPMDEP_SENSE_REQUIRES;
335 sense = RPMDEP_SENSE_REQUIRES;
336 if ((needsVersion = strrchr(needsName, ' ')) != NULL)
337 *needsVersion++ = '\0';
340 if ((needsOP = strrchr(needsName, ' ')) != NULL) {
341 for (*needsOP++ = '\0'; *needsOP != '\0'; needsOP++) {
342 if (*needsOP == '<') needsFlags |= RPMSENSE_LESS;
343 else if (*needsOP == '>') needsFlags |= RPMSENSE_GREATER;
344 else if (*needsOP == '=') needsFlags |= RPMSENSE_EQUAL;
348 cf = Py_BuildValue("((sss)(ss)iOi)", byName, byVersion, byRelease,
349 needsName, needsVersion, needsFlags,
350 (key != NULL ? key : Py_None),
352 PyList_Append(list, (PyObject *) cf);
358 psi = rpmpsFreeIterator(psi);
368 rpmts_Order(rpmtsObject * s)
372 Py_BEGIN_ALLOW_THREADS
373 rc = rpmtsOrder(s->ts);
376 return Py_BuildValue("i", rc);
380 rpmts_Clean(rpmtsObject * s)
388 rpmts_OpenDB(rpmtsObject * s)
392 dbmode = rpmtsGetDBMode(s->ts);
396 return Py_BuildValue("i", rpmtsOpenDB(s->ts, dbmode));
400 rpmts_CloseDB(rpmtsObject * s)
404 rc = rpmtsCloseDB(s->ts);
405 rpmtsSetDBMode(s->ts, -1); /* XXX disable lazy opens */
407 return Py_BuildValue("i", rc);
411 rpmts_InitDB(rpmtsObject * s)
415 rc = rpmtsInitDB(s->ts, O_RDONLY);
417 rc = rpmtsCloseDB(s->ts);
419 return Py_BuildValue("i", rc);
423 rpmts_RebuildDB(rpmtsObject * s)
427 Py_BEGIN_ALLOW_THREADS
428 rc = rpmtsRebuildDB(s->ts);
431 return Py_BuildValue("i", rc);
435 rpmts_VerifyDB(rpmtsObject * s)
439 Py_BEGIN_ALLOW_THREADS
440 rc = rpmtsVerifyDB(s->ts);
443 return Py_BuildValue("i", rc);
447 rpmts_HdrFromFdno(rpmtsObject * s, PyObject * args, PyObject * kwds)
449 PyObject * result = NULL;
453 char * kwlist[] = {"fd", NULL};
455 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:HdrFromFdno", kwlist,
456 rpmFdFromPyObject, &fd))
459 rpmrc = rpmReadPackageFile(s->ts, fd, "rpmts_HdrFromFdno", &h);
465 result = Py_BuildValue("N", hdr_Wrap(&hdr_Type, h));
466 h = headerFree(h); /* XXX ref held by result */
470 PyErr_SetString(pyrpmError, "public key not available");
473 case RPMRC_NOTTRUSTED:
474 PyErr_SetString(pyrpmError, "public key not trusted");
480 PyErr_SetString(pyrpmError, "error reading package header");
488 rpmts_HdrCheck(rpmtsObject * s, PyObject * args, PyObject * kwds)
491 PyObject * result = NULL;
496 char * kwlist[] = {"headers", NULL};
498 if (!PyArg_ParseTupleAndKeywords(args, kwds, "S:HdrCheck", kwlist, &blob))
501 uh = PyString_AsString(blob);
502 uc = PyString_Size(blob);
504 rpmrc = headerCheck(s->ts, uh, uc, &msg);
513 PyErr_SetString(pyrpmError, "public key not availaiable");
516 case RPMRC_NOTTRUSTED:
517 PyErr_SetString(pyrpmError, "public key not trusted");
522 PyErr_SetString(pyrpmError, msg);
531 rpmts_SetVSFlags(rpmtsObject * s, PyObject * args, PyObject * kwds)
534 char * kwlist[] = {"flags", NULL};
536 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:SetVSFlags", kwlist,
540 /* XXX FIXME: value check on vsflags, or build pure python object
541 * for it, and require an object of that type */
543 return Py_BuildValue("i", rpmtsSetVSFlags(s->ts, vsflags));
547 rpmts_GetVSFlags(rpmtsObject * s)
549 return Py_BuildValue("i", rpmtsVSFlags(s->ts));
553 rpmts_SetColor(rpmtsObject * s, PyObject * args, PyObject * kwds)
556 char * kwlist[] = {"color", NULL};
558 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:Color", kwlist, &tscolor))
561 /* XXX FIXME: value check on tscolor, or build pure python object
562 * for it, and require an object of that type */
564 return Py_BuildValue("i", rpmtsSetColor(s->ts, tscolor));
568 rpmts_PgpPrtPkts(rpmtsObject * s, PyObject * args, PyObject * kwds)
574 char * kwlist[] = {"octets", NULL};
576 if (!PyArg_ParseTupleAndKeywords(args, kwds, "S:PgpPrtPkts", kwlist, &blob))
579 pkt = (unsigned char *)PyString_AsString(blob);
580 pktlen = PyString_Size(blob);
582 rc = pgpPrtPkts(pkt, pktlen, NULL, 1);
584 return Py_BuildValue("i", rc);
588 rpmts_PgpImportPubkey(rpmtsObject * s, PyObject * args, PyObject * kwds)
594 char * kwlist[] = {"pubkey", NULL};
596 if (!PyArg_ParseTupleAndKeywords(args, kwds, "S:PgpImportPubkey",
600 pkt = (unsigned char *)PyString_AsString(blob);
601 pktlen = PyString_Size(blob);
603 rc = rpmtsImportPubkey(s->ts, pkt, pktlen);
605 return Py_BuildValue("i", rc);
609 rpmts_GetKeys(rpmtsObject * s)
611 const void **data = NULL;
615 rpmtsGetKeys(s->ts, &data, &num);
616 if (data == NULL || num <= 0) {
621 tuple = PyTuple_New(num);
623 for (i = 0; i < num; i++) {
625 obj = (data[i] ? (PyObject *) data[i] : Py_None);
627 PyTuple_SetItem(tuple, i, obj);
636 rpmtsCallback(const void * hd, const rpmCallbackType what,
637 const rpm_loff_t amount, const rpm_loff_t total,
638 const void * pkgKey, rpmCallbackData data)
640 Header h = (Header) hd;
641 struct rpmtsCallbackType_s * cbInfo = data;
642 PyObject * pkgObj = (PyObject *) pkgKey;
643 PyObject * args, * result;
646 if (cbInfo->cb == Py_None) return NULL;
648 /* Synthesize a python object for callback (if necessary). */
649 if (pkgObj == NULL) {
651 pkgObj = Py_BuildValue("s", headerGetString(h, RPMTAG_NAME));
659 PyEval_RestoreThread(cbInfo->_save);
661 args = Py_BuildValue("(iLLOO)", what, amount, total, pkgObj, cbInfo->data);
662 result = PyEval_CallObject(cbInfo->cb, args);
670 if (what == RPMCALLBACK_INST_OPEN_FILE) {
673 if (!PyArg_Parse(result, "i", &fdno)) {
677 cbInfo->_save = PyEval_SaveThread();
680 fcntl(Fileno(fd), F_SETFD, FD_CLOEXEC);
684 if (what == RPMCALLBACK_INST_CLOSE_FILE) {
689 cbInfo->_save = PyEval_SaveThread();
695 rpmts_SetFlags(rpmtsObject * s, PyObject * args, PyObject * kwds)
697 rpmtransFlags transFlags = 0;
698 char * kwlist[] = {"flags", NULL};
700 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:SetFlags", kwlist,
704 /* XXX FIXME: value check on flags, or build pure python object
705 * for it, and require an object of that type */
707 return Py_BuildValue("i", rpmtsSetFlags(s->ts, transFlags));
711 rpmts_SetProbFilter(rpmtsObject * s, PyObject * args, PyObject * kwds)
713 rpmprobFilterFlags ignoreSet = 0;
714 rpmprobFilterFlags oignoreSet;
715 char * kwlist[] = {"ignoreSet", NULL};
717 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:ProbFilter", kwlist,
721 oignoreSet = s->ignoreSet;
722 s->ignoreSet = ignoreSet;
724 return Py_BuildValue("i", oignoreSet);
728 rpmts_Problems(rpmtsObject * s)
730 return rpmps_Wrap(&rpmps_Type, rpmtsProblems(s->ts));
734 rpmts_Run(rpmtsObject * s, PyObject * args, PyObject * kwds)
740 struct rpmtsCallbackType_s cbInfo;
741 char * kwlist[] = {"callback", "data", NULL};
743 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO:Run", kwlist,
744 &cbInfo.cb, &cbInfo.data))
748 cbInfo._save = PyEval_SaveThread();
750 if (cbInfo.cb != NULL) {
751 if (!PyCallable_Check(cbInfo.cb)) {
752 PyErr_SetString(PyExc_TypeError, "expected a callable");
755 (void) rpmtsSetNotifyCallback(s->ts, rpmtsCallback, (void *) &cbInfo);
758 rc = rpmtsRun(s->ts, NULL, s->ignoreSet);
759 ps = rpmtsProblems(s->ts);
762 (void) rpmtsSetNotifyCallback(s->ts, NULL, NULL);
764 PyEval_RestoreThread(cbInfo._save);
767 list = PyList_New(0);
773 list = PyList_New(0);
774 psi = rpmpsInitIterator(ps);
775 while (rpmpsNextIterator(psi) >= 0) {
776 rpmProblem p = rpmpsGetProblem(psi);
777 char * ps = rpmProblemString(p);
778 PyObject * prob = Py_BuildValue("s(isN)", ps,
779 rpmProblemGetType(p),
781 PyLong_FromLongLong(rpmProblemGetDiskNeed(p)));
782 PyList_Append(list, prob);
787 psi = rpmpsFreeIterator(psi);
794 rpmts_iternext(rpmtsObject * s)
796 PyObject * result = NULL;
799 /* Reset iterator on 1st entry. */
800 if (s->tsi == NULL) {
801 s->tsi = rpmtsiInit(s->ts);
806 te = rpmtsiNext(s->tsi, 0);
808 result = rpmte_Wrap(&rpmte_Type, te);
810 s->tsi = rpmtsiFree(s->tsi);
817 spec_Parse(rpmtsObject * s, PyObject * args, PyObject * kwds)
820 /* we could pass in the ts from here but hardly worth the trouble */
821 return PyObject_Call((PyObject *) &spec_Type, args, kwds);
825 rpmts_Match(rpmtsObject * s, PyObject * args, PyObject * kwds)
827 PyObject *Key = NULL;
829 /* XXX lkey *must* be a 32 bit integer, int "works" on all known platforms. */
832 rpmTag tag = RPMDBI_PACKAGES;
833 char * kwlist[] = {"tagNumber", "key", NULL};
835 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O:Match", kwlist,
836 tagNumFromPyObject, &tag, &Key))
840 if (PyString_Check(Key)) {
841 key = PyString_AsString(Key);
842 len = PyString_Size(Key);
843 } else if (PyInt_Check(Key)) {
844 lkey = PyInt_AsLong(Key);
848 PyErr_SetString(PyExc_TypeError, "unknown key type");
851 /* One of the conversions above failed, exception is set already */
852 if (PyErr_Occurred()) {
857 /* XXX If not already opened, open the database O_RDONLY now. */
858 /* XXX FIXME: lazy default rdonly open also done by rpmtsInitIterator(). */
859 if (rpmtsGetRdb(s->ts) == NULL) {
860 int rc = rpmtsOpenDB(s->ts, O_RDONLY);
861 if (rc || rpmtsGetRdb(s->ts) == NULL) {
862 PyErr_SetString(PyExc_TypeError, "rpmdb open failed");
867 return rpmmi_Wrap(&rpmmi_Type, rpmtsInitIterator(s->ts, tag, key, len), (PyObject*)s);
870 static struct PyMethodDef rpmts_methods[] = {
871 {"addInstall", (PyCFunction) rpmts_AddInstall, METH_VARARGS|METH_KEYWORDS,
873 {"addErase", (PyCFunction) rpmts_AddErase, METH_VARARGS|METH_KEYWORDS,
875 {"check", (PyCFunction) rpmts_Check, METH_VARARGS|METH_KEYWORDS,
877 {"order", (PyCFunction) rpmts_Order, METH_NOARGS,
879 {"setFlags", (PyCFunction) rpmts_SetFlags, METH_VARARGS|METH_KEYWORDS,
880 "ts.setFlags(transFlags) -> previous transFlags\n\
881 - Set control bit(s) for executing ts.run().\n\
882 Note: This method replaces the 1st argument to the old ts.run()\n" },
883 {"setProbFilter", (PyCFunction) rpmts_SetProbFilter, METH_VARARGS|METH_KEYWORDS,
884 "ts.setProbFilter(ignoreSet) -> previous ignoreSet\n\
885 - Set control bit(s) for ignoring problems found by ts.run().\n\
886 Note: This method replaces the 2nd argument to the old ts.run()\n" },
887 {"problems", (PyCFunction) rpmts_Problems, METH_NOARGS,
888 "ts.problems() -> ps\n\
889 - Return current problem set.\n" },
890 {"run", (PyCFunction) rpmts_Run, METH_VARARGS|METH_KEYWORDS,
891 "ts.run(callback, data) -> (problems)\n\
892 - Run a transaction set, returning list of problems found.\n\
893 Note: The callback may not be None.\n" },
894 {"clean", (PyCFunction) rpmts_Clean, METH_NOARGS,
896 {"openDB", (PyCFunction) rpmts_OpenDB, METH_NOARGS,
897 "ts.openDB() -> None\n\
898 - Open the default transaction rpmdb.\n\
899 Note: The transaction rpmdb is lazily opened, so ts.openDB() is seldom needed.\n" },
900 {"closeDB", (PyCFunction) rpmts_CloseDB, METH_NOARGS,
901 "ts.closeDB() -> None\n\
902 - Close the default transaction rpmdb.\n\
903 Note: ts.closeDB() disables lazy opens, and should hardly ever be used.\n" },
904 {"initDB", (PyCFunction) rpmts_InitDB, METH_NOARGS,
905 "ts.initDB() -> None\n\
906 - Initialize the default transaction rpmdb.\n\
907 Note: ts.initDB() is seldom needed anymore.\n" },
908 {"rebuildDB", (PyCFunction) rpmts_RebuildDB, METH_NOARGS,
909 "ts.rebuildDB() -> None\n\
910 - Rebuild the default transaction rpmdb.\n" },
911 {"verifyDB", (PyCFunction) rpmts_VerifyDB, METH_NOARGS,
912 "ts.verifyDB() -> None\n\
913 - Verify the default transaction rpmdb.\n" },
914 {"hdrFromFdno",(PyCFunction) rpmts_HdrFromFdno,METH_VARARGS|METH_KEYWORDS,
915 "ts.hdrFromFdno(fdno) -> hdr\n\
916 - Read a package header from a file descriptor.\n" },
917 {"hdrCheck", (PyCFunction) rpmts_HdrCheck, METH_VARARGS|METH_KEYWORDS,
919 {"setVSFlags",(PyCFunction) rpmts_SetVSFlags, METH_VARARGS|METH_KEYWORDS,
920 "ts.setVSFlags(vsflags) -> ovsflags\n\
921 - Set signature verification flags. Values for vsflags are:\n\
922 rpm.RPMVSF_NOHDRCHK if set, don't check rpmdb headers\n\
923 rpm.RPMVSF_NEEDPAYLOAD if not set, check header+payload (if possible)\n\
924 rpm.RPMVSF_NOSHA1HEADER if set, don't check header SHA1 digest\n\
925 rpm.RPMVSF_NODSAHEADER if set, don't check header DSA signature\n\
926 rpm.RPMVSF_NOMD5 if set, don't check header+payload MD5 digest\n\
927 rpm.RPMVSF_NODSA if set, don't check header+payload DSA signature\n\
928 rpm.RPMVSF_NORSA if set, don't check header+payload RSA signature\n\
929 rpm._RPMVSF_NODIGESTS if set, don't check digest(s)\n\
930 rpm._RPMVSF_NOSIGNATURES if set, don't check signature(s)\n" },
931 {"getVSFlags",(PyCFunction) rpmts_GetVSFlags, METH_NOARGS,
932 "ts.getVSFlags() -> vsflags\n\
933 - Retrieve current signature verification flags from transaction\n" },
934 {"setColor",(PyCFunction) rpmts_SetColor, METH_VARARGS|METH_KEYWORDS,
936 {"pgpPrtPkts", (PyCFunction) rpmts_PgpPrtPkts, METH_VARARGS|METH_KEYWORDS,
938 {"pgpImportPubkey", (PyCFunction) rpmts_PgpImportPubkey, METH_VARARGS|METH_KEYWORDS,
940 {"getKeys", (PyCFunction) rpmts_GetKeys, METH_NOARGS,
942 {"parseSpec", (PyCFunction) spec_Parse, METH_VARARGS|METH_KEYWORDS,
943 "ts.parseSpec(\"/path/to/foo.spec\") -> spec\n\
944 - Parse a spec file.\n" },
945 {"dbMatch", (PyCFunction) rpmts_Match, METH_VARARGS|METH_KEYWORDS,
946 "ts.dbMatch([TagN, [key, [len]]]) -> mi\n\
947 - Create a match iterator for the default transaction rpmdb.\n" },
948 {NULL, NULL} /* sentinel */
951 static void rpmts_dealloc(rpmtsObject * s)
954 s->ts = rpmtsFree(s->ts);
956 if (s->scriptFd) Fclose(s->scriptFd);
957 /* this will free the keyList, and decrement the ref count of all
958 the items on the list as well :-) */
959 Py_DECREF(s->keyList);
960 s->ob_type->tp_free((PyObject *)s);
963 static PyObject * rpmts_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
965 char * rootDir = "/";
966 rpmVSFlags vsflags = rpmExpandNumeric("%{?__vsflags}");
967 char * kwlist[] = {"rootdir", "vsflags", 0};
970 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|si:rpmts_new", kwlist,
975 /* XXX: Why is there no rpmts_SetRootDir() ? */
976 (void) rpmtsSetRootDir(ts, rootDir);
977 /* XXX: make this use common code with rpmts_SetVSFlags() to check the
979 (void) rpmtsSetVSFlags(ts, vsflags);
981 return rpmts_Wrap(subtype, ts);
984 static int rpmts_set_scriptFd(rpmtsObject *s, PyObject *value, void *closure)
987 if (PyArg_Parse(value, "O&", rpmFdFromPyObject, &s->scriptFd)) {
988 rpmtsSetScriptFd(s->ts, s->scriptFd);
989 } else if (value == Py_None) {
992 rpmtsSetScriptFd(s->ts, NULL);
999 static char rpmts_doc[] =
1002 static PyGetSetDef rpmts_getseters[] = {
1003 /* only provide a setter until we have rpmfd wrappings */
1004 {"scriptFd", NULL, (setter)rpmts_set_scriptFd, NULL },
1008 PyTypeObject rpmts_Type = {
1009 PyObject_HEAD_INIT(&PyType_Type)
1011 "rpm.ts", /* tp_name */
1012 sizeof(rpmtsObject), /* tp_size */
1013 0, /* tp_itemsize */
1014 (destructor) rpmts_dealloc, /* tp_dealloc */
1016 (getattrfunc)0, /* tp_getattr */
1017 (setattrfunc)0, /* tp_setattr */
1020 0, /* tp_as_number */
1021 0, /* tp_as_sequence */
1022 0, /* tp_as_mapping */
1026 PyObject_GenericGetAttr, /* tp_getattro */
1027 PyObject_GenericSetAttr, /* tp_setattro */
1028 0, /* tp_as_buffer */
1029 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1030 rpmts_doc, /* tp_doc */
1031 0, /* tp_traverse */
1033 0, /* tp_richcompare */
1034 0, /* tp_weaklistoffset */
1035 PyObject_SelfIter, /* tp_iter */
1036 (iternextfunc) rpmts_iternext, /* tp_iternext */
1037 rpmts_methods, /* tp_methods */
1039 rpmts_getseters, /* tp_getset */
1042 0, /* tp_descr_get */
1043 0, /* tp_descr_set */
1044 0, /* tp_dictoffset */
1047 (newfunc) rpmts_new, /* tp_new */
1053 rpmts_Create(PyObject * self, PyObject * args, PyObject * kwds)
1055 return PyObject_Call((PyObject *) &rpmts_Type, args, kwds);
1058 PyObject * rpmts_Wrap(PyTypeObject *subtype, rpmts ts)
1060 rpmtsObject * s = (rpmtsObject *)subtype->tp_alloc(subtype, 0);
1061 if (s == NULL) return PyErr_NoMemory();
1064 s->keyList = PyList_New(0);
1067 return (PyObject *) s;