9 #define _RPMPS_INTERNAL
23 #define _RPMTS_INTERNAL
178 PyObject * args, * result;
182 fprintf(stderr,
"*** rpmts_SolveCallback(%p,%p,%p) \"%s\"\n", ts, ds, data,
rpmdsDNEVR(ds));
184 if (cbInfo->
tso == NULL)
return res;
186 if (cbInfo->
cb == Py_None)
return res;
188 PyEval_RestoreThread(cbInfo->
_save);
191 args = Py_BuildValue(
"(OO)", cbInfo->
tso, cbInfo->
dso);
192 result = PyEval_CallObject(cbInfo->
cb, args);
193 Py_DECREF(cbInfo->
dso);
200 if (PyInt_Check(result))
201 res = PyInt_AsLong(result);
205 cbInfo->
_save = PyEval_SaveThread();
215 const unsigned long long amount,
const unsigned long long total,
224 PyObject * pkgObj = (PyObject *) pkgKey;
225 PyObject * oh = NULL;
226 const char * origin = NULL;
227 PyObject * args, * result;
228 unsigned long oamount = amount;
229 unsigned long ototal = total;
233 if (cbInfo->
cb == Py_None)
return NULL;
236 if (pkgObj == NULL) {
238 const char * n = NULL;
240 pkgObj = Py_BuildValue(
"s", n);
248 if (!(PyTuple_Check(pkgObj) && PyArg_ParseTuple(pkgObj,
"|Os", &oh, &origin)))
251 if (origin && origin[0] ==
'/' && origin[1] ==
'/')
255 PyEval_RestoreThread(cbInfo->
_save);
257 args = Py_BuildValue(
"(illOO)", what, oamount, ototal, pkgObj, cbInfo->
data);
258 result = PyEval_CallObject(cbInfo->
cb, args);
264 cbInfo->
_save = PyEval_SaveThread();
271 if (!PyArg_Parse(result,
"i", &fdno)) {
273 cbInfo->
_save = PyEval_SaveThread();
277 cbInfo->
_save = PyEval_SaveThread();
281 fprintf(stderr,
"\t%p = fdDup(%d)\n", fd, fdno);
283 fcntl(
Fileno(fd), F_SETFD, FD_CLOEXEC);
292 fprintf(stderr,
"\tFclose(%p)\n", fd);
296 fprintf(stderr,
"\t%lu:%lu key %p\n", oamount, ototal, pkgKey);
300 cbInfo->
_save = PyEval_SaveThread();
327 fprintf(stderr,
"\tAddAvailable(%p) list %p\n", ts, ts->availablePackages);
331 #if Py_TPFLAGS_HAVE_ITER
339 fprintf(stderr,
"*** rpmts_iter(%p) ts %p\n", s, s->
ts);
342 return (PyObject *)s;
354 PyObject * result = NULL;
358 fprintf(stderr,
"*** rpmts_iternext(%p) ts %p tsi %p %d\n", s, s->
ts, s->
tsi, s->
tsiFilter);
361 if (s->
tsi == NULL) {
394 char * kwlist[] = {
"debugLevel", NULL};
396 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i:Debug", kwlist,
401 fprintf(stderr,
"*** rpmts_Debug(%p) ts %p\n", s, s->
ts);
419 char * kwlist[] = {
"header",
"key",
"how", NULL};
421 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O!O|s:AddInstall", kwlist,
425 { PyObject * hObj = (PyObject *) h;
427 PyErr_SetString(PyExc_TypeError,
"bad type for header argument");
433 fprintf(stderr,
"*** rpmts_AddInstall(%p,%p,%p,%s) ts %p\n", s, h, key, how, s->
ts);
435 if (how && strcmp(how,
"a") && strcmp(how,
"u") && strcmp(how,
"i")) {
436 PyErr_SetString(PyExc_TypeError,
"how argument must be \"u\", \"a\", or \"i\"");
438 }
else if (how && !strcmp(how,
"u"))
441 if (how && !strcmp(how,
"a"))
448 PyList_Append(s->
keyList, key);
466 char * kwlist[] = {
"name", NULL};
469 fprintf(stderr,
"*** rpmts_AddErase(%p) ts %p\n", s, s->
ts);
471 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O:AddErase", kwlist, &o))
474 if (PyString_Check(o) || PyUnicode_Check(o)) {
475 char *
name = PyString_AsString(o);
481 PyErr_SetString(
pyrpmError,
"package not installed");
493 if (PyInt_Check(o)) {
494 uint_32 instance = PyInt_AsLong(o);
497 if (instance == 0 || mi == NULL) {
499 PyErr_SetString(
pyrpmError,
"package not installed");
527 PyObject * list, * cf;
531 char * kwlist[] = {
"callback", NULL};
533 memset(&cbInfo, 0,
sizeof(cbInfo));
534 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|O:Check", kwlist,
538 if (cbInfo.
cb != NULL) {
539 if (!PyCallable_Check(cbInfo.
cb)) {
540 PyErr_SetString(PyExc_TypeError,
"expected a callable");
547 fprintf(stderr,
"*** rpmts_Check(%p) ts %p cb %p\n", s, s->
ts, cbInfo.
cb);
552 cbInfo.
_save = PyEval_SaveThread();
563 PyEval_RestoreThread(cbInfo.
_save);
566 list = PyList_New(0);
569 for (i = 0; i < ps->numProblems; i++) {
571 cf = Py_BuildValue(
"((sss)(ss)iOi)", conflicts[i].byName,
572 conflicts[i].byVersion, conflicts[i].byRelease,
574 conflicts[i].needsName,
575 conflicts[i].needsVersion,
577 conflicts[i].needsFlags,
578 conflicts[i].suggestedPkgs ?
579 conflicts[i].suggestedPkgs[0] : Py_None,
582 char * byName, * byVersion, * byRelease, *byArch;
583 char * needsName, * needsOP, * needsVersion;
584 int needsFlags, sense;
594 if ((byArch= strrchr(byName,
'.')) != NULL)
596 if ((byRelease = strrchr(byName,
'-')) != NULL)
598 if ((byVersion = strrchr(byName,
'-')) != NULL)
603 needsName = p->altNEVR;
604 if (needsName[1] ==
' ') {
605 sense = (needsName[0] ==
'C')
610 if ((needsVersion = strrchr(needsName,
' ')) != NULL)
611 *needsVersion++ =
'\0';
614 if ((needsOP = strrchr(needsName,
' ')) != NULL) {
615 for (*needsOP++ =
'\0'; *needsOP !=
'\0'; needsOP++) {
622 cf = Py_BuildValue(
"((sss)(ss)iOi)", byName, byVersion, byRelease,
623 needsName, needsVersion, needsFlags,
624 (key != NULL ? key : Py_None),
627 PyList_Append(list, (PyObject *) cf);
651 fprintf(stderr,
"*** rpmts_Order(%p) ts %p\n", s, s->
ts);
653 Py_BEGIN_ALLOW_THREADS
657 return Py_BuildValue(
"i", rc);
669 fprintf(stderr,
"*** rpmts_Clean(%p) ts %p\n", s, s->
ts);
685 PyObject * result = NULL;
687 char * kwlist[] = {
"rbtid", NULL};
692 fprintf(stderr,
"*** rpmts_IDTXload(%p) ts %p\n", s, s->
ts);
694 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i:IDTXload", kwlist, &rbtid))
697 Py_BEGIN_ALLOW_THREADS
702 if (idtx == NULL || idtx->nidt <= 0) {
711 result = PyTuple_New(idtx->nidt);
712 for (i = 0; i < idtx->nidt; i++) {
716 PyTuple_SET_ITEM(result, i, tuple);
735 PyObject * result = NULL;
736 const char * globstr;
738 char * kwlist[] = {
"rbtid", NULL};
743 fprintf(stderr,
"*** rpmts_IDTXglob(%p) ts %p\n", s, s->
ts);
745 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i:IDTXglob", kwlist, &rbtid))
748 Py_BEGIN_ALLOW_THREADS
749 globstr =
rpmExpand(
"%{_repackage_dir}/*.rpm", NULL);
751 globstr =
_free(globstr);
755 if (idtx == NULL || idtx->
nidt <= 0) {
764 result = PyTuple_New(idtx->
nidt);
765 for (i = 0; i < idtx->
nidt; i++) {
768 tuple = Py_BuildValue(
"(iOs)", idt->
val.
u32, ho, idt->
key);
769 PyTuple_SET_ITEM(result, i, tuple);
788 QVA_t ia = memset(
alloca(
sizeof(*ia)), 0,
sizeof(*ia));
790 const char ** av = NULL;
793 char * kwlist[] = {
"transactionId", NULL};
796 fprintf(stderr,
"*** rpmts_Rollback(%p) ts %p\n", s, s->
ts);
798 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i:Rollback", kwlist, &rbtid))
801 Py_BEGIN_ALLOW_THREADS
815 return Py_BuildValue(
"i", rc);
828 fprintf(stderr,
"*** rpmts_OpenDB(%p) ts %p\n", s, s->
ts);
830 if (s->
ts->dbmode == -1)
831 s->
ts->dbmode = O_RDONLY;
846 fprintf(stderr,
"*** rpmts_CloseDB(%p) ts %p\n", s, s->
ts);
851 return Py_BuildValue(
"i", rc);
865 fprintf(stderr,
"*** rpmts_InitDB(%p) ts %p\n", s, s->
ts);
871 return Py_BuildValue(
"i", rc);
885 fprintf(stderr,
"*** rpmts_RebuildDB(%p) ts %p\n", s, s->
ts);
887 Py_BEGIN_ALLOW_THREADS
891 return Py_BuildValue(
"i", rc);
905 fprintf(stderr,
"*** rpmts_VerifyDB(%p) ts %p\n", s, s->
ts);
907 Py_BEGIN_ALLOW_THREADS
911 return Py_BuildValue(
"i", rc);
922 PyObject * result = NULL;
927 char * kwlist[] = {
"fd", NULL};
929 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i:HdrFromFdno", kwlist,
938 fprintf(stderr,
"*** rpmts_HdrFromFdno(%p) ts %p rc %d\n", s, s->
ts, rpmrc);
944 result = Py_BuildValue(
"N",
hdr_Wrap(h));
949 PyErr_SetString(
pyrpmError,
"public key not available");
953 PyErr_SetString(
pyrpmError,
"public key not trusted");
959 PyErr_SetString(
pyrpmError,
"error reading package header");
976 PyObject * result = NULL;
977 const char * msg = NULL;
981 char * kwlist[] = {
"headers", NULL};
984 fprintf(stderr,
"*** rpmts_HdrCheck(%p) ts %p\n", s, s->
ts);
986 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O:HdrCheck", kwlist, &blob))
989 if (blob == Py_None) {
993 if (!(PyString_Check(blob) || PyUnicode_Check(blob))) {
994 PyErr_SetString(
pyrpmError,
"hdrCheck takes a string of octets");
997 uh = PyString_AsString(blob);
998 uc = PyString_Size(blob);
1009 PyErr_SetString(
pyrpmError,
"public key not availaiable");
1013 PyErr_SetString(
pyrpmError,
"public key not trusted");
1034 char * kwlist[] = {
"flags", NULL};
1037 fprintf(stderr,
"*** rpmts_SetVSFlags(%p) ts %p\n", s, s->
ts);
1039 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i:SetVSFlags", kwlist,
1057 char * kwlist[] = {
"color", NULL};
1060 fprintf(stderr,
"*** rpmts_SetColor(%p) ts %p\n", s, s->
ts);
1062 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i:Color", kwlist, &tscolor))
1080 unsigned char * pkt;
1081 unsigned int pktlen;
1083 char * kwlist[] = {
"octets", NULL};
1086 fprintf(stderr,
"*** rpmts_PgpPrtPkts(%p) ts %p\n", s, s->
ts);
1088 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O:PgpPrtPkts", kwlist, &blob))
1091 if (blob == Py_None) {
1095 if (!(PyString_Check(blob) || PyUnicode_Check(blob))) {
1096 PyErr_SetString(
pyrpmError,
"pgpPrtPkts takes a string of octets");
1099 pkt = (
unsigned char *) PyString_AsString(blob);
1100 pktlen = PyString_Size(blob);
1104 return Py_BuildValue(
"i", rc);
1116 unsigned char * pkt;
1117 unsigned int pktlen;
1119 char * kwlist[] = {
"pubkey", NULL};
1122 fprintf(stderr,
"*** rpmts_PgpImportPubkey(%p) ts %p\n", s, s->
ts);
1124 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O:PgpImportPubkey",
1128 if (blob == Py_None) {
1132 if (!(PyString_Check(blob) || PyUnicode_Check(blob))) {
1133 PyErr_SetString(
pyrpmError,
"PgpImportPubkey takes a string of octets");
1136 pkt = (
unsigned char *) PyString_AsString(blob);
1137 pktlen = PyString_Size(blob);
1141 return Py_BuildValue(
"i", rc);
1151 char * kwlist[] = {
"flags", NULL};
1153 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i:SetFlags", kwlist,
1158 fprintf(stderr,
"*** rpmts_SetFlags(%p) ts %p transFlags 0x%x\n", s, s->
ts, transFlags);
1173 char * kwlist[] = {
"flags", NULL};
1175 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i:SetDFlags", kwlist,
1180 fprintf(stderr,
"*** rpmts_SetDFlags(%p) ts %p depFlags 0x%x\n", s, s->
ts, depFlags);
1196 char * kwlist[] = {
"ignoreSet", NULL};
1198 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i:ProbFilter", kwlist,
1203 fprintf(stderr,
"*** rpmts_SetProbFilter(%p) ts %p ignoreSet %x\n", s, s->
ts, ignoreSet);
1208 return Py_BuildValue(
"i", oignoreSet);
1220 fprintf(stderr,
"*** rpmts_Problems(%p) ts %p\n", s, s->
ts);
1236 char * kwlist[] = {
"callback",
"data", NULL};
1238 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"OO:Run", kwlist,
1239 &cbInfo.
cb, &cbInfo.
data))
1245 cbInfo.
_save = PyEval_SaveThread();
1247 if (cbInfo.
cb != NULL) {
1248 if (!PyCallable_Check(cbInfo.
cb)) {
1249 PyErr_SetString(PyExc_TypeError,
"expected a callable");
1257 const char *fn =
rpmGetPath(
"%{?_install_file_context_path}", NULL);
1258 if (fn != NULL && *fn !=
'\0')
1264 fprintf(stderr,
"*** rpmts_Run(%p) ts %p ignore %x\n", s, s->
ts, s->
ignoreSet);
1272 PyEval_RestoreThread(cbInfo.
_save);
1280 list = PyList_New(0);
1287 list = PyList_New(0);
1288 for (i = 0; i < ps->numProblems; i++) {
1290 unsigned long ulong1 = p->ulong1;
1294 PyLong_FromLongLong(ulong1));
1295 PyList_Append(list, prob);
1315 fprintf(stderr,
"*** rpmts_Next(%p) ts %p\n", s, s->
ts);
1319 if (result == NULL) {
1335 const char * specfile;
1338 char * passPhrase =
"";
1339 char *cookie = NULL;
1343 char * kwlist[] = {
"specfile", NULL};
1345 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s:Parse", kwlist, &specfile))
1348 if (
parseSpec(s->
ts, specfile,
"/", recursing, passPhrase,
1349 cookie, anyarch, force, verify)!=0) {
1350 PyErr_SetString(
pyrpmError,
"can't parse specfile\n");
1355 return spec_Wrap(spec);
1366 PyObject *TagN = NULL;
1367 PyObject *Key = NULL;
1373 char * kwlist[] = {
"tagNumber",
"key", NULL};
1376 fprintf(stderr,
"*** rpmts_Match(%p) ts %p\n", s, s->
ts);
1378 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|OO:Match", kwlist,
1383 PyErr_SetString(PyExc_TypeError,
"unknown tag type");
1389 if (PyString_Check(Key) || PyUnicode_Check(Key)) {
1390 key = PyString_AsString(Key);
1391 len = PyString_Size(Key);
1392 }
else if (PyInt_Check(Key)) {
1393 lkey = PyInt_AsLong(Key);
1394 key = (
char *)&lkey;
1397 PyErr_SetString(PyExc_TypeError,
"unknown key type");
1405 if (s->
ts->rdb == NULL) {
1407 if (rc || s->
ts->rdb == NULL) {
1408 PyErr_SetString(PyExc_TypeError,
"rpmdb open failed");
1423 {
"Debug", (PyCFunction)
rpmts_Debug, METH_VARARGS|METH_KEYWORDS,
1428 {
"addErase", (PyCFunction)
rpmts_AddErase, METH_VARARGS|METH_KEYWORDS,
1430 {
"setDFlags", (PyCFunction)
rpmts_SetDFlags, METH_VARARGS|METH_KEYWORDS,
1431 "ts.setDFlags(depFlags) -> previous depFlags\n\
1432 - Set control bit(s) for executing ts.check() and ts.order().\n" },
1433 {
"check", (PyCFunction)
rpmts_Check, METH_VARARGS|METH_KEYWORDS,
1437 {
"setFlags", (PyCFunction)
rpmts_SetFlags, METH_VARARGS|METH_KEYWORDS,
1438 "ts.setFlags(transFlags) -> previous transFlags\n\
1439 - Set control bit(s) for executing ts.run().\n\
1440 Note: This method replaces the 1st argument to the old ts.run()\n" },
1442 "ts.setProbFilter(ignoreSet) -> previous ignoreSet\n\
1443 - Set control bit(s) for ignoring problems found by ts.run().\n\
1444 Note: This method replaces the 2nd argument to the old ts.run()\n" },
1446 "ts.problems() -> ps\n\
1447 - Return current problem set.\n" },
1448 {
"run", (PyCFunction)
rpmts_Run, METH_VARARGS|METH_KEYWORDS,
1449 "ts.run(callback, data) -> (problems)\n\
1450 - Run a transaction set, returning list of problems found.\n\
1451 Note: The callback may not be None.\n" },
1454 {
"IDTXload", (PyCFunction)
rpmts_IDTXload, METH_VARARGS|METH_KEYWORDS,
1455 "ts.IDTXload(rbtid=iid) -> ((tid,hdr,instance)+)\n\
1456 - Return list of installed packages reverse sorted by transaction id.\n" },
1457 {
"IDTXglob", (PyCFunction)
rpmts_IDTXglob, METH_VARARGS|METH_KEYWORDS,
1458 "ts.IDTXglob(rbtid=rid) -> ((tid,hdr,instance)+)\n\
1459 - Return list of removed packages reverse sorted by transaction id.\n" },
1460 {
"rollback", (PyCFunction)
rpmts_Rollback, METH_VARARGS|METH_KEYWORDS,
1463 "ts.openDB() -> None\n\
1464 - Open the default transaction rpmdb.\n\
1465 Note: The transaction rpmdb is lazily opened, so ts.openDB() is seldom needed.\n" },
1467 "ts.closeDB() -> None\n\
1468 - Close the default transaction rpmdb.\n\
1469 Note: ts.closeDB() disables lazy opens, and should hardly ever be used.\n" },
1471 "ts.initDB() -> None\n\
1472 - Initialize the default transaction rpmdb.\n\
1473 Note: ts.initDB() is seldom needed anymore.\n" },
1475 "ts.rebuildDB() -> None\n\
1476 - Rebuild the default transaction rpmdb.\n" },
1478 "ts.verifyDB() -> None\n\
1479 - Verify the default transaction rpmdb.\n" },
1481 "ts.hdrFromFdno(fdno) -> hdr\n\
1482 - Read a package header from a file descriptor.\n" },
1483 {
"hdrCheck", (PyCFunction)
rpmts_HdrCheck, METH_VARARGS|METH_KEYWORDS,
1486 "ts.setVSFlags(vsflags) -> ovsflags\n\
1487 - Set signature verification flags. Values for vsflags are:\n\
1488 rpm.RPMVSF_NOHDRCHK if set, don't check rpmdb headers\n\
1489 rpm.RPMVSF_NEEDPAYLOAD if not set, check header+payload (if possible)\n\
1490 rpm.RPMVSF_NOSHA1HEADER if set, don't check header SHA1 digest\n\
1491 rpm.RPMVSF_NODSAHEADER if set, don't check header DSA signature\n\
1492 rpm.RPMVSF_NORSAHEADER if set, don't check header RSA signature\n\
1493 rpm.RPMVSF_NOMD5 if set, don't check header+payload MD5 digest\n\
1494 rpm.RPMVSF_NODSA if set, don't check header+payload DSA signature\n\
1495 rpm.RPMVSF_NORSA if set, don't check header+payload RSA signature\n\
1496 rpm._RPMVSF_NODIGESTS if set, don't check digest(s)\n\
1497 rpm._RPMVSF_NOSIGNATURES if set, don't check signature(s)\n" },
1498 {
"setColor",(PyCFunction)
rpmts_SetColor, METH_VARARGS|METH_KEYWORDS,
1504 {
"parseSpec", (PyCFunction)
spec_Parse, METH_VARARGS|METH_KEYWORDS,
1505 "ts.parseSpec(\"/path/to/foo.spec\") -> spec\n\
1506 - Parse a spec file.\n" },
1507 {
"dbMatch", (PyCFunction)
rpmts_Match, METH_VARARGS|METH_KEYWORDS,
1508 "ts.dbMatch([TagN, [key, [len]]]) -> mi\n\
1509 - Create a match iterator for the default transaction rpmdb.\n" },
1510 {
"next", (PyCFunction)
rpmts_Next, METH_NOARGS,
1512 - Retrieve next transaction set element.\n" },
1524 fprintf(stderr,
"%p -- ts %p db %p\n", s, s->
ts, s->
ts->rdb);
1531 PyObject_Del((PyObject *)s);
1537 return PyObject_GenericGetAttr(o, n);
1546 char *
name = PyString_AsString(n);
1549 if (!strcmp(name,
"scriptFd")) {
1550 if (!PyArg_Parse(v,
"i", &fdno))
return 0;
1552 PyErr_SetString(PyExc_TypeError,
"bad file descriptor");
1559 PyErr_SetString(PyExc_AttributeError, name);
1572 char * rootDir =
"/";
1574 char * kwlist[] = {
"rootdir",
"vsflags", 0};
1577 fprintf(stderr,
"*** rpmts_init(%p,%p,%p)\n", s, args, kwds);
1579 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|si:rpmts_init", kwlist,
1580 &rootDir, &vsflags))
1603 fprintf(stderr,
"%p -- ts %p db %p\n", s, s->
ts, s->
ts->rdb);
1613 PyObject_Del((PyObject *)s);
1621 PyObject * s = PyType_GenericAlloc(subtype, nitems);
1624 fprintf(stderr,
"*** rpmts_alloc(%p,%d) ret %p\n", subtype, nitems, s);
1630 static PyObject *
rpmts_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
1643 fprintf(stderr,
"%p ++ ts %p db %p\n", s, s->
ts, s->
ts->rdb);
1645 return (PyObject *)s;
1658 PyObject_HEAD_INIT(&PyType_Type)
1680 #if Py_TPFLAGS_HAVE_ITER
1711 char * rootDir =
"/";
1713 char * kwlist[] = {
"rootdir",
"vsflags", NULL};
1715 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|si:Create", kwlist,
1716 &rootDir, &vsflags))
1719 o = (
void *) PyObject_New(
rpmtsObject, &rpmts_Type);
1734 fprintf(stderr,
"%p ++ ts %p db %p\n", o, o->
ts, o->
ts->rdb);