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 rpmElementType tsiFilter;
145 rpmprobFilterFlags ignoreSet;
148 struct rpmtsCallbackType_s {
152 PyThreadState *_save;
156 static void die(PyObject *cb)
161 if (PyErr_Occurred()) {
164 if ((r = PyObject_Repr(cb)) != NULL) {
165 pyfn = PyString_AsString(r);
167 fprintf(stderr, _("error: python callback %s failed, aborting!\n"),
168 pyfn ? pyfn : "???");
169 rpmdbCheckTerminate(1);
174 rpmts_AddInstall(rpmtsObject * s, PyObject * args, PyObject * kwds)
178 char * how = "u"; /* XXX default to upgrade element if missing */
180 char * kwlist[] = {"header", "key", "how", NULL};
183 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O|s:AddInstall", kwlist,
184 &hdr_Type, &h, &key, &how))
187 if (how && !rstreq(how, "u") && !rstreq(how, "i")) {
188 PyErr_SetString(PyExc_TypeError, "how argument must be \"u\" or \"i\"");
190 } else if (how && rstreq(how, "u"))
193 rc = rpmtsAddInstallElement(s->ts, hdrGetHeader(h), key, isUpgrade, NULL);
195 PyErr_SetString(pyrpmError, "adding package to transaction failed");
200 /* This should increment the usage count for me */
202 PyList_Append(s->keyList, key);
207 /* TODO Permit finer control (i.e. not just --allmatches) of deleted elments.*/
209 rpmts_AddErase(rpmtsObject * s, PyObject * args, PyObject * kwds)
213 rpmdbMatchIterator mi = NULL;
215 char * kwlist[] = {"name", NULL};
217 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:AddErase", kwlist, &o))
220 if (PyString_Check(o)) {
221 char * name = PyString_AsString(o);
222 mi = rpmtsInitIterator(s->ts, RPMDBI_LABEL, name, 0);
223 } else if (PyInt_Check(o)) {
224 uint32_t recno = PyInt_AsLong(o);
225 mi = rpmtsInitIterator(s->ts, RPMDBI_PACKAGES, &recno, sizeof(recno));
227 PyErr_SetString(PyExc_TypeError, "string or integer expected");
231 while ((h = rpmdbNextIterator(mi)) != NULL) {
233 rpmtsAddEraseElement(s->ts, h, -1);
235 rpmdbFreeIterator(mi);
240 PyErr_SetString(pyrpmError, "package not installed");
246 rpmts_SolveCallback(rpmts ts, rpmds ds, const void * data)
248 struct rpmtsCallbackType_s * cbInfo = (struct rpmtsCallbackType_s *) data;
249 PyObject * args, * result;
252 if (cbInfo->tso == NULL) return res;
253 if (cbInfo->cb == Py_None) return res;
255 PyEval_RestoreThread(cbInfo->_save);
257 args = Py_BuildValue("(Oissi)", cbInfo->tso,
258 rpmdsTagN(ds), rpmdsN(ds), rpmdsEVR(ds), rpmdsFlags(ds));
259 result = PyEval_CallObject(cbInfo->cb, args);
265 if (PyInt_Check(result))
266 res = PyInt_AsLong(result);
270 cbInfo->_save = PyEval_SaveThread();
276 rpmts_Check(rpmtsObject * s, PyObject * args, PyObject * kwds)
280 PyObject * list, * cf;
281 struct rpmtsCallbackType_s cbInfo;
283 char * kwlist[] = {"callback", NULL};
285 memset(&cbInfo, 0, sizeof(cbInfo));
286 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:Check", kwlist,
290 if (cbInfo.cb != NULL) {
291 if (!PyCallable_Check(cbInfo.cb)) {
292 PyErr_SetString(PyExc_TypeError, "expected a callable");
295 xx = rpmtsSetSolveCallback(s->ts, rpmts_SolveCallback, (void *)&cbInfo);
299 cbInfo._save = PyEval_SaveThread();
301 xx = rpmtsCheck(s->ts);
302 ps = rpmtsProblems(s->ts);
304 PyEval_RestoreThread(cbInfo._save);
307 list = PyList_New(0);
308 rpmpsi psi = rpmpsInitIterator(ps);
310 /* XXX TODO: rpmlib >= 4.0.3 can return multiple suggested keys. */
311 while (rpmpsNextIterator(psi) >= 0) {
312 char * altNEVR, * needsName;
313 char * byName, * byVersion, * byRelease, *byArch;
314 char * needsOP, * needsVersion;
315 rpmsenseFlags needsFlags, sense;
318 p = rpmpsGetProblem(psi);
320 byName = xstrdup(rpmProblemGetPkgNEVR(p));
321 if ((byArch= strrchr(byName, '.')) != NULL)
323 if ((byRelease = strrchr(byName, '-')) != NULL)
325 if ((byVersion = strrchr(byName, '-')) != NULL)
328 key = rpmProblemGetKey(p);
330 altNEVR = needsName = xstrdup(rpmProblemGetAltNEVR(p));
331 if (needsName[1] == ' ') {
332 sense = (needsName[0] == 'C')
333 ? RPMDEP_SENSE_CONFLICTS : RPMDEP_SENSE_REQUIRES;
336 sense = RPMDEP_SENSE_REQUIRES;
337 if ((needsVersion = strrchr(needsName, ' ')) != NULL)
338 *needsVersion++ = '\0';
341 if ((needsOP = strrchr(needsName, ' ')) != NULL) {
342 for (*needsOP++ = '\0'; *needsOP != '\0'; needsOP++) {
343 if (*needsOP == '<') needsFlags |= RPMSENSE_LESS;
344 else if (*needsOP == '>') needsFlags |= RPMSENSE_GREATER;
345 else if (*needsOP == '=') needsFlags |= RPMSENSE_EQUAL;
349 cf = Py_BuildValue("((sss)(ss)iOi)", byName, byVersion, byRelease,
350 needsName, needsVersion, needsFlags,
351 (key != NULL ? key : Py_None),
353 PyList_Append(list, (PyObject *) cf);
359 psi = rpmpsFreeIterator(psi);
369 rpmts_Order(rpmtsObject * s)
373 Py_BEGIN_ALLOW_THREADS
374 rc = rpmtsOrder(s->ts);
377 return Py_BuildValue("i", rc);
381 rpmts_Clean(rpmtsObject * s)
389 rpmts_OpenDB(rpmtsObject * s)
393 dbmode = rpmtsGetDBMode(s->ts);
397 return Py_BuildValue("i", rpmtsOpenDB(s->ts, dbmode));
401 rpmts_CloseDB(rpmtsObject * s)
405 rc = rpmtsCloseDB(s->ts);
406 rpmtsSetDBMode(s->ts, -1); /* XXX disable lazy opens */
408 return Py_BuildValue("i", rc);
412 rpmts_InitDB(rpmtsObject * s)
416 rc = rpmtsInitDB(s->ts, O_RDONLY);
418 rc = rpmtsCloseDB(s->ts);
420 return Py_BuildValue("i", rc);
424 rpmts_RebuildDB(rpmtsObject * s)
428 Py_BEGIN_ALLOW_THREADS
429 rc = rpmtsRebuildDB(s->ts);
432 return Py_BuildValue("i", rc);
436 rpmts_VerifyDB(rpmtsObject * s)
440 Py_BEGIN_ALLOW_THREADS
441 rc = rpmtsVerifyDB(s->ts);
444 return Py_BuildValue("i", rc);
448 rpmts_HdrFromFdno(rpmtsObject * s, PyObject * args, PyObject * kwds)
450 PyObject * result = NULL;
454 char * kwlist[] = {"fd", NULL};
456 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:HdrFromFdno", kwlist,
457 rpmFdFromPyObject, &fd))
460 rpmrc = rpmReadPackageFile(s->ts, fd, "rpmts_HdrFromFdno", &h);
466 result = Py_BuildValue("N", hdr_Wrap(&hdr_Type, h));
467 h = headerFree(h); /* XXX ref held by result */
471 PyErr_SetString(pyrpmError, "public key not available");
474 case RPMRC_NOTTRUSTED:
475 PyErr_SetString(pyrpmError, "public key not trusted");
481 PyErr_SetString(pyrpmError, "error reading package header");
489 rpmts_HdrCheck(rpmtsObject * s, PyObject * args, PyObject * kwds)
492 PyObject * result = NULL;
497 char * kwlist[] = {"headers", NULL};
499 if (!PyArg_ParseTupleAndKeywords(args, kwds, "S:HdrCheck", kwlist, &blob))
502 uh = PyString_AsString(blob);
503 uc = PyString_Size(blob);
505 rpmrc = headerCheck(s->ts, uh, uc, &msg);
514 PyErr_SetString(pyrpmError, "public key not availaiable");
517 case RPMRC_NOTTRUSTED:
518 PyErr_SetString(pyrpmError, "public key not trusted");
523 PyErr_SetString(pyrpmError, msg);
532 rpmts_SetVSFlags(rpmtsObject * s, PyObject * args, PyObject * kwds)
535 char * kwlist[] = {"flags", NULL};
537 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:SetVSFlags", kwlist,
541 /* XXX FIXME: value check on vsflags, or build pure python object
542 * for it, and require an object of that type */
544 return Py_BuildValue("i", rpmtsSetVSFlags(s->ts, vsflags));
548 rpmts_GetVSFlags(rpmtsObject * s)
550 return Py_BuildValue("i", rpmtsVSFlags(s->ts));
554 rpmts_SetColor(rpmtsObject * s, PyObject * args, PyObject * kwds)
557 char * kwlist[] = {"color", NULL};
559 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:Color", kwlist, &tscolor))
562 /* XXX FIXME: value check on tscolor, or build pure python object
563 * for it, and require an object of that type */
565 return Py_BuildValue("i", rpmtsSetColor(s->ts, tscolor));
569 rpmts_PgpPrtPkts(rpmtsObject * s, PyObject * args, PyObject * kwds)
575 char * kwlist[] = {"octets", NULL};
577 if (!PyArg_ParseTupleAndKeywords(args, kwds, "S:PgpPrtPkts", kwlist, &blob))
580 pkt = (unsigned char *)PyString_AsString(blob);
581 pktlen = PyString_Size(blob);
583 rc = pgpPrtPkts(pkt, pktlen, NULL, 1);
585 return Py_BuildValue("i", rc);
589 rpmts_PgpImportPubkey(rpmtsObject * s, PyObject * args, PyObject * kwds)
595 char * kwlist[] = {"pubkey", NULL};
597 if (!PyArg_ParseTupleAndKeywords(args, kwds, "S:PgpImportPubkey",
601 pkt = (unsigned char *)PyString_AsString(blob);
602 pktlen = PyString_Size(blob);
604 rc = rpmtsImportPubkey(s->ts, pkt, pktlen);
606 return Py_BuildValue("i", rc);
610 rpmts_GetKeys(rpmtsObject * s)
612 const void **data = NULL;
616 rpmtsGetKeys(s->ts, &data, &num);
617 if (data == NULL || num <= 0) {
622 tuple = PyTuple_New(num);
624 for (i = 0; i < num; i++) {
626 obj = (data[i] ? (PyObject *) data[i] : Py_None);
628 PyTuple_SetItem(tuple, i, obj);
637 rpmtsCallback(const void * hd, const rpmCallbackType what,
638 const rpm_loff_t amount, const rpm_loff_t total,
639 const void * pkgKey, rpmCallbackData data)
641 Header h = (Header) hd;
642 struct rpmtsCallbackType_s * cbInfo = data;
643 PyObject * pkgObj = (PyObject *) pkgKey;
644 PyObject * args, * result;
647 if (cbInfo->cb == Py_None) return NULL;
649 /* Synthesize a python object for callback (if necessary). */
650 if (pkgObj == NULL) {
652 pkgObj = Py_BuildValue("s", headerGetString(h, RPMTAG_NAME));
660 PyEval_RestoreThread(cbInfo->_save);
662 args = Py_BuildValue("(iLLOO)", what, amount, total, pkgObj, cbInfo->data);
663 result = PyEval_CallObject(cbInfo->cb, args);
671 if (what == RPMCALLBACK_INST_OPEN_FILE) {
674 if (!PyArg_Parse(result, "i", &fdno)) {
678 cbInfo->_save = PyEval_SaveThread();
681 fcntl(Fileno(fd), F_SETFD, FD_CLOEXEC);
685 if (what == RPMCALLBACK_INST_CLOSE_FILE) {
690 cbInfo->_save = PyEval_SaveThread();
696 rpmts_SetFlags(rpmtsObject * s, PyObject * args, PyObject * kwds)
698 rpmtransFlags transFlags = 0;
699 char * kwlist[] = {"flags", NULL};
701 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:SetFlags", kwlist,
705 /* XXX FIXME: value check on flags, or build pure python object
706 * for it, and require an object of that type */
708 return Py_BuildValue("i", rpmtsSetFlags(s->ts, transFlags));
712 rpmts_SetProbFilter(rpmtsObject * s, PyObject * args, PyObject * kwds)
714 rpmprobFilterFlags ignoreSet = 0;
715 rpmprobFilterFlags oignoreSet;
716 char * kwlist[] = {"ignoreSet", NULL};
718 if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:ProbFilter", kwlist,
722 oignoreSet = s->ignoreSet;
723 s->ignoreSet = ignoreSet;
725 return Py_BuildValue("i", oignoreSet);
729 rpmts_Problems(rpmtsObject * s)
731 return rpmps_Wrap(&rpmps_Type, rpmtsProblems(s->ts));
735 rpmts_Run(rpmtsObject * s, PyObject * args, PyObject * kwds)
741 struct rpmtsCallbackType_s cbInfo;
742 char * kwlist[] = {"callback", "data", NULL};
744 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO:Run", kwlist,
745 &cbInfo.cb, &cbInfo.data))
749 cbInfo._save = PyEval_SaveThread();
751 if (cbInfo.cb != NULL) {
752 if (!PyCallable_Check(cbInfo.cb)) {
753 PyErr_SetString(PyExc_TypeError, "expected a callable");
756 (void) rpmtsSetNotifyCallback(s->ts, rpmtsCallback, (void *) &cbInfo);
759 rc = rpmtsRun(s->ts, NULL, s->ignoreSet);
760 ps = rpmtsProblems(s->ts);
763 (void) rpmtsSetNotifyCallback(s->ts, NULL, NULL);
765 PyEval_RestoreThread(cbInfo._save);
768 list = PyList_New(0);
774 list = PyList_New(0);
775 psi = rpmpsInitIterator(ps);
776 while (rpmpsNextIterator(psi) >= 0) {
777 rpmProblem p = rpmpsGetProblem(psi);
778 char * ps = rpmProblemString(p);
779 PyObject * prob = Py_BuildValue("s(isN)", ps,
780 rpmProblemGetType(p),
782 PyLong_FromLongLong(rpmProblemGetDiskNeed(p)));
783 PyList_Append(list, prob);
788 psi = rpmpsFreeIterator(psi);
794 /* TODO Add TR_ADDED filter to iterator. */
796 rpmts_iternext(rpmtsObject * s)
798 PyObject * result = NULL;
801 /* Reset iterator on 1st entry. */
802 if (s->tsi == NULL) {
803 s->tsi = rpmtsiInit(s->ts);
809 te = rpmtsiNext(s->tsi, s->tsiFilter);
811 result = rpmte_Wrap(&rpmte_Type, te);
813 s->tsi = rpmtsiFree(s->tsi);
821 spec_Parse(rpmtsObject * s, PyObject * args, PyObject * kwds)
824 /* we could pass in the ts from here but hardly worth the trouble */
825 return PyObject_Call((PyObject *) &spec_Type, args, kwds);
829 rpmts_Match(rpmtsObject * s, PyObject * args, PyObject * kwds)
831 PyObject *Key = NULL;
833 /* XXX lkey *must* be a 32 bit integer, int "works" on all known platforms. */
836 rpmTag tag = RPMDBI_PACKAGES;
837 char * kwlist[] = {"tagNumber", "key", NULL};
839 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O:Match", kwlist,
840 tagNumFromPyObject, &tag, &Key))
844 if (PyString_Check(Key)) {
845 key = PyString_AsString(Key);
846 len = PyString_Size(Key);
847 } else if (PyInt_Check(Key)) {
848 lkey = PyInt_AsLong(Key);
852 PyErr_SetString(PyExc_TypeError, "unknown key type");
855 /* One of the conversions above failed, exception is set already */
856 if (PyErr_Occurred()) {
861 /* XXX If not already opened, open the database O_RDONLY now. */
862 /* XXX FIXME: lazy default rdonly open also done by rpmtsInitIterator(). */
863 if (rpmtsGetRdb(s->ts) == NULL) {
864 int rc = rpmtsOpenDB(s->ts, O_RDONLY);
865 if (rc || rpmtsGetRdb(s->ts) == NULL) {
866 PyErr_SetString(PyExc_TypeError, "rpmdb open failed");
871 return rpmmi_Wrap(&rpmmi_Type, rpmtsInitIterator(s->ts, tag, key, len), (PyObject*)s);
874 static struct PyMethodDef rpmts_methods[] = {
875 {"addInstall", (PyCFunction) rpmts_AddInstall, METH_VARARGS|METH_KEYWORDS,
877 {"addErase", (PyCFunction) rpmts_AddErase, METH_VARARGS|METH_KEYWORDS,
879 {"check", (PyCFunction) rpmts_Check, METH_VARARGS|METH_KEYWORDS,
881 {"order", (PyCFunction) rpmts_Order, METH_NOARGS,
883 {"setFlags", (PyCFunction) rpmts_SetFlags, METH_VARARGS|METH_KEYWORDS,
884 "ts.setFlags(transFlags) -> previous transFlags\n\
885 - Set control bit(s) for executing ts.run().\n\
886 Note: This method replaces the 1st argument to the old ts.run()\n" },
887 {"setProbFilter", (PyCFunction) rpmts_SetProbFilter, METH_VARARGS|METH_KEYWORDS,
888 "ts.setProbFilter(ignoreSet) -> previous ignoreSet\n\
889 - Set control bit(s) for ignoring problems found by ts.run().\n\
890 Note: This method replaces the 2nd argument to the old ts.run()\n" },
891 {"problems", (PyCFunction) rpmts_Problems, METH_NOARGS,
892 "ts.problems() -> ps\n\
893 - Return current problem set.\n" },
894 {"run", (PyCFunction) rpmts_Run, METH_VARARGS|METH_KEYWORDS,
895 "ts.run(callback, data) -> (problems)\n\
896 - Run a transaction set, returning list of problems found.\n\
897 Note: The callback may not be None.\n" },
898 {"clean", (PyCFunction) rpmts_Clean, METH_NOARGS,
900 {"openDB", (PyCFunction) rpmts_OpenDB, METH_NOARGS,
901 "ts.openDB() -> None\n\
902 - Open the default transaction rpmdb.\n\
903 Note: The transaction rpmdb is lazily opened, so ts.openDB() is seldom needed.\n" },
904 {"closeDB", (PyCFunction) rpmts_CloseDB, METH_NOARGS,
905 "ts.closeDB() -> None\n\
906 - Close the default transaction rpmdb.\n\
907 Note: ts.closeDB() disables lazy opens, and should hardly ever be used.\n" },
908 {"initDB", (PyCFunction) rpmts_InitDB, METH_NOARGS,
909 "ts.initDB() -> None\n\
910 - Initialize the default transaction rpmdb.\n\
911 Note: ts.initDB() is seldom needed anymore.\n" },
912 {"rebuildDB", (PyCFunction) rpmts_RebuildDB, METH_NOARGS,
913 "ts.rebuildDB() -> None\n\
914 - Rebuild the default transaction rpmdb.\n" },
915 {"verifyDB", (PyCFunction) rpmts_VerifyDB, METH_NOARGS,
916 "ts.verifyDB() -> None\n\
917 - Verify the default transaction rpmdb.\n" },
918 {"hdrFromFdno",(PyCFunction) rpmts_HdrFromFdno,METH_VARARGS|METH_KEYWORDS,
919 "ts.hdrFromFdno(fdno) -> hdr\n\
920 - Read a package header from a file descriptor.\n" },
921 {"hdrCheck", (PyCFunction) rpmts_HdrCheck, METH_VARARGS|METH_KEYWORDS,
923 {"setVSFlags",(PyCFunction) rpmts_SetVSFlags, METH_VARARGS|METH_KEYWORDS,
924 "ts.setVSFlags(vsflags) -> ovsflags\n\
925 - Set signature verification flags. Values for vsflags are:\n\
926 rpm.RPMVSF_NOHDRCHK if set, don't check rpmdb headers\n\
927 rpm.RPMVSF_NEEDPAYLOAD if not set, check header+payload (if possible)\n\
928 rpm.RPMVSF_NOSHA1HEADER if set, don't check header SHA1 digest\n\
929 rpm.RPMVSF_NODSAHEADER if set, don't check header DSA signature\n\
930 rpm.RPMVSF_NOMD5 if set, don't check header+payload MD5 digest\n\
931 rpm.RPMVSF_NODSA if set, don't check header+payload DSA signature\n\
932 rpm.RPMVSF_NORSA if set, don't check header+payload RSA signature\n\
933 rpm._RPMVSF_NODIGESTS if set, don't check digest(s)\n\
934 rpm._RPMVSF_NOSIGNATURES if set, don't check signature(s)\n" },
935 {"getVSFlags",(PyCFunction) rpmts_GetVSFlags, METH_NOARGS,
936 "ts.getVSFlags() -> vsflags\n\
937 - Retrieve current signature verification flags from transaction\n" },
938 {"setColor",(PyCFunction) rpmts_SetColor, METH_VARARGS|METH_KEYWORDS,
940 {"pgpPrtPkts", (PyCFunction) rpmts_PgpPrtPkts, METH_VARARGS|METH_KEYWORDS,
942 {"pgpImportPubkey", (PyCFunction) rpmts_PgpImportPubkey, METH_VARARGS|METH_KEYWORDS,
944 {"getKeys", (PyCFunction) rpmts_GetKeys, METH_NOARGS,
946 {"parseSpec", (PyCFunction) spec_Parse, METH_VARARGS|METH_KEYWORDS,
947 "ts.parseSpec(\"/path/to/foo.spec\") -> spec\n\
948 - Parse a spec file.\n" },
949 {"dbMatch", (PyCFunction) rpmts_Match, METH_VARARGS|METH_KEYWORDS,
950 "ts.dbMatch([TagN, [key, [len]]]) -> mi\n\
951 - Create a match iterator for the default transaction rpmdb.\n" },
952 {NULL, NULL} /* sentinel */
955 static void rpmts_dealloc(rpmtsObject * s)
958 s->ts = rpmtsFree(s->ts);
960 if (s->scriptFd) Fclose(s->scriptFd);
961 /* this will free the keyList, and decrement the ref count of all
962 the items on the list as well :-) */
963 Py_DECREF(s->keyList);
964 s->ob_type->tp_free((PyObject *)s);
967 static PyObject * rpmts_getattro(PyObject * o, PyObject * n)
969 return PyObject_GenericGetAttr(o, n);
972 static int rpmts_setattro(PyObject * o, PyObject * n, PyObject * v)
974 rpmtsObject *s = (rpmtsObject *)o;
975 char * name = PyString_AsString(n);
978 /* XXX TODO: eliminate this hackery */
979 if (rstreq(name, "scriptFd")) {
980 if (!PyArg_Parse(v, "i", &fdno)) return -1;
982 PyErr_SetString(PyExc_TypeError, "bad file descriptor");
985 s->scriptFd = fdDup(fdno);
986 rpmtsSetScriptFd(s->ts, s->scriptFd);
989 return PyObject_GenericSetAttr(o, n, v);
995 static PyObject * rpmts_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
997 char * rootDir = "/";
998 rpmVSFlags vsflags = rpmExpandNumeric("%{?__vsflags}");
999 char * kwlist[] = {"rootdir", "vsflags", 0};
1002 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|si:rpmts_new", kwlist,
1003 &rootDir, &vsflags))
1007 /* XXX: Why is there no rpmts_SetRootDir() ? */
1008 (void) rpmtsSetRootDir(ts, rootDir);
1009 /* XXX: make this use common code with rpmts_SetVSFlags() to check the
1011 (void) rpmtsSetVSFlags(ts, vsflags);
1013 return rpmts_Wrap(subtype, ts);
1016 static char rpmts_doc[] =
1019 PyTypeObject rpmts_Type = {
1020 PyObject_HEAD_INIT(&PyType_Type)
1022 "rpm.ts", /* tp_name */
1023 sizeof(rpmtsObject), /* tp_size */
1024 0, /* tp_itemsize */
1025 (destructor) rpmts_dealloc, /* tp_dealloc */
1027 (getattrfunc)0, /* tp_getattr */
1028 (setattrfunc)0, /* tp_setattr */
1031 0, /* tp_as_number */
1032 0, /* tp_as_sequence */
1033 0, /* tp_as_mapping */
1037 (getattrofunc) rpmts_getattro, /* tp_getattro */
1038 (setattrofunc) rpmts_setattro, /* tp_setattro */
1039 0, /* tp_as_buffer */
1040 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1041 rpmts_doc, /* tp_doc */
1042 0, /* tp_traverse */
1044 0, /* tp_richcompare */
1045 0, /* tp_weaklistoffset */
1046 PyObject_SelfIter, /* tp_iter */
1047 (iternextfunc) rpmts_iternext, /* tp_iternext */
1048 rpmts_methods, /* tp_methods */
1053 0, /* tp_descr_get */
1054 0, /* tp_descr_set */
1055 0, /* tp_dictoffset */
1058 (newfunc) rpmts_new, /* tp_new */
1064 rpmts_Create(PyObject * self, PyObject * args, PyObject * kwds)
1066 return PyObject_Call((PyObject *) &rpmts_Type, args, kwds);
1069 PyObject * rpmts_Wrap(PyTypeObject *subtype, rpmts ts)
1071 rpmtsObject * s = (rpmtsObject *)subtype->tp_alloc(subtype, 0);
1072 if (s == NULL) return PyErr_NoMemory();
1075 s->keyList = PyList_New(0);
1079 return (PyObject *) s;