Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/rpm-software-management/createrepo_c.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleš Matěj <amatej@redhat.com>2022-03-09 17:23:47 +0300
committerLukáš Hrázký <lhrazky@redhat.com>2022-06-06 18:53:48 +0300
commit3d3dc6b7bf722b08c07003003e5d8cc0aa7eb1ee (patch)
tree717f7abeaa076c4258543310507850c4bde77a55
parentb2b80e3b57615aee491d2e384d55e73045b27cca (diff)
Revert "Wrap c api to python for parsing metadata together"
This reverts commit 670006b9f37d8298fe2ec1d6cfc5cdf175a3128b.
-rw-r--r--src/python/createrepo_cmodule.c2
-rw-r--r--src/python/xml_parser-py.c156
-rw-r--r--src/python/xml_parser-py.h8
3 files changed, 32 insertions, 134 deletions
diff --git a/src/python/createrepo_cmodule.c b/src/python/createrepo_cmodule.c
index c0b9200..6937246 100644
--- a/src/python/createrepo_cmodule.c
+++ b/src/python/createrepo_cmodule.c
@@ -79,8 +79,6 @@ static struct PyMethodDef createrepo_c_methods[] = {
METH_VARARGS, xml_parse_repomd__doc__},
{"xml_parse_updateinfo", (PyCFunction)py_xml_parse_updateinfo,
METH_VARARGS, xml_parse_updateinfo__doc__},
- {"xml_parse_main_metadata_together",(PyCFunctionWithKeywords)py_xml_parse_main_metadata_together,
- METH_VARARGS | METH_KEYWORDS, xml_parse_main_metadata_together__doc__},
{"checksum_name_str", (PyCFunction)py_checksum_name_str,
METH_VARARGS, checksum_name_str__doc__},
{"checksum_type", (PyCFunction)py_checksum_type,
diff --git a/src/python/xml_parser-py.c b/src/python/xml_parser-py.c
index a1f92f8..0879128 100644
--- a/src/python/xml_parser-py.c
+++ b/src/python/xml_parser-py.c
@@ -34,7 +34,7 @@ typedef struct {
PyObject *py_newpkgcb;
PyObject *py_pkgcb;
PyObject *py_warningcb;
- PyObject *py_pkgs; /*!< Current processed package */
+ PyObject *py_pkg; /*!< Current processed package */
} CbData;
static int
@@ -48,6 +48,12 @@ c_newpkgcb(cr_Package **pkg,
PyObject *arglist, *result;
CbData *data = cbdata;
+ if (data->py_pkg) {
+ // Decref ref count on previous processed package
+ Py_DECREF(data->py_pkg);
+ data->py_pkg = NULL;
+ }
+
arglist = Py_BuildValue("(sss)", pkgId, name, arch);
result = PyObject_CallObject(data->py_newpkgcb, arglist);
Py_DECREF(arglist);
@@ -67,18 +73,13 @@ c_newpkgcb(cr_Package **pkg,
if (result == Py_None) {
*pkg = NULL;
+ data->py_pkg = NULL;
+ Py_DECREF(result);
} else {
*pkg = Package_FromPyObject(result);
- if (data->py_pkgcb != Py_None) {
- // Store reference to the python pkg (result) only if we will need it later
- PyObject *keyFromPtr = PyLong_FromVoidPtr(*pkg);
- PyDict_SetItem(data->py_pkgs, keyFromPtr, result);
- Py_DECREF(keyFromPtr);
- }
+ data->py_pkg = result; // Store reference to current package
}
- Py_DECREF(result);
-
return CR_CB_RET_OK;
}
@@ -90,23 +91,16 @@ c_pkgcb(cr_Package *pkg,
PyObject *arglist, *result, *py_pkg;
CbData *data = cbdata;
- PyObject *keyFromPtr = PyLong_FromVoidPtr(pkg);
- py_pkg = PyDict_GetItem(data->py_pkgs, keyFromPtr);
- if (py_pkg) {
- arglist = Py_BuildValue("(O)", py_pkg);
- result = PyObject_CallObject(data->py_pkgcb, arglist);
- PyDict_DelItem(data->py_pkgs, keyFromPtr);
- } else {
- // The package was not provided by user in c_newpkgcb,
- // create new python package object
- PyObject *new_py_pkg = Object_FromPackage(pkg, 1);
- arglist = Py_BuildValue("(O)", new_py_pkg);
- result = PyObject_CallObject(data->py_pkgcb, arglist);
- Py_DECREF(new_py_pkg);
- }
+ if (data->py_pkg)
+ py_pkg = data->py_pkg;
+ else
+ py_pkg = Object_FromPackage(pkg, 1);
+ arglist = Py_BuildValue("(O)", py_pkg);
+ result = PyObject_CallObject(data->py_pkgcb, arglist);
Py_DECREF(arglist);
- Py_DECREF(keyFromPtr);
+ Py_DECREF(py_pkg);
+ data->py_pkg = NULL;
if (result == NULL) {
// Exception raised
@@ -197,7 +191,7 @@ py_xml_parse_primary(G_GNUC_UNUSED PyObject *self, PyObject *args)
cbdata.py_newpkgcb = py_newpkgcb;
cbdata.py_pkgcb = py_pkgcb;
cbdata.py_warningcb = py_warningcb;
- cbdata.py_pkgs = PyDict_New();
+ cbdata.py_pkg = NULL;
cr_xml_parse_primary(filename,
ptr_c_newpkgcb,
@@ -212,8 +206,7 @@ py_xml_parse_primary(G_GNUC_UNUSED PyObject *self, PyObject *args)
Py_XDECREF(py_newpkgcb);
Py_XDECREF(py_pkgcb);
Py_XDECREF(py_warningcb);
-
- Py_XDECREF(cbdata.py_pkgs);
+ Py_XDECREF(cbdata.py_pkg);
if (tmp_err) {
nice_exception(&tmp_err, NULL);
@@ -279,7 +272,7 @@ py_xml_parse_primary_snippet(G_GNUC_UNUSED PyObject *self, PyObject *args)
cbdata.py_newpkgcb = py_newpkgcb;
cbdata.py_pkgcb = py_pkgcb;
cbdata.py_warningcb = py_warningcb;
- cbdata.py_pkgs = PyDict_New();
+ cbdata.py_pkg = NULL;
cr_xml_parse_primary_snippet(target, ptr_c_newpkgcb, &cbdata, ptr_c_pkgcb, &cbdata,
ptr_c_warningcb, &cbdata, do_files, &tmp_err);
@@ -287,7 +280,7 @@ py_xml_parse_primary_snippet(G_GNUC_UNUSED PyObject *self, PyObject *args)
Py_XDECREF(py_newpkgcb);
Py_XDECREF(py_pkgcb);
Py_XDECREF(py_warningcb);
- Py_XDECREF(cbdata.py_pkgs);
+ Py_XDECREF(cbdata.py_pkg);
if (tmp_err) {
nice_exception(&tmp_err, NULL);
@@ -351,7 +344,7 @@ py_xml_parse_filelists(G_GNUC_UNUSED PyObject *self, PyObject *args)
cbdata.py_newpkgcb = py_newpkgcb;
cbdata.py_pkgcb = py_pkgcb;
cbdata.py_warningcb = py_warningcb;
- cbdata.py_pkgs = PyDict_New();
+ cbdata.py_pkg = NULL;
cr_xml_parse_filelists(filename,
ptr_c_newpkgcb,
@@ -365,7 +358,7 @@ py_xml_parse_filelists(G_GNUC_UNUSED PyObject *self, PyObject *args)
Py_XDECREF(py_newpkgcb);
Py_XDECREF(py_pkgcb);
Py_XDECREF(py_warningcb);
- Py_XDECREF(cbdata.py_pkgs);
+ Py_XDECREF(cbdata.py_pkg);
if (tmp_err) {
nice_exception(&tmp_err, NULL);
@@ -429,7 +422,7 @@ py_xml_parse_filelists_snippet(G_GNUC_UNUSED PyObject *self, PyObject *args)
cbdata.py_newpkgcb = py_newpkgcb;
cbdata.py_pkgcb = py_pkgcb;
cbdata.py_warningcb = py_warningcb;
- cbdata.py_pkgs = PyDict_New();
+ cbdata.py_pkg = NULL;
cr_xml_parse_filelists_snippet(target, ptr_c_newpkgcb, &cbdata, ptr_c_pkgcb,
&cbdata, ptr_c_warningcb, &cbdata, &tmp_err);
@@ -437,7 +430,7 @@ py_xml_parse_filelists_snippet(G_GNUC_UNUSED PyObject *self, PyObject *args)
Py_XDECREF(py_newpkgcb);
Py_XDECREF(py_pkgcb);
Py_XDECREF(py_warningcb);
- Py_XDECREF(cbdata.py_pkgs);
+ Py_XDECREF(cbdata.py_pkg);
if (tmp_err) {
nice_exception(&tmp_err, NULL);
@@ -501,7 +494,7 @@ py_xml_parse_other(G_GNUC_UNUSED PyObject *self, PyObject *args)
cbdata.py_newpkgcb = py_newpkgcb;
cbdata.py_pkgcb = py_pkgcb;
cbdata.py_warningcb = py_warningcb;
- cbdata.py_pkgs = PyDict_New();
+ cbdata.py_pkg = NULL;
cr_xml_parse_other(filename,
ptr_c_newpkgcb,
@@ -515,7 +508,7 @@ py_xml_parse_other(G_GNUC_UNUSED PyObject *self, PyObject *args)
Py_XDECREF(py_newpkgcb);
Py_XDECREF(py_pkgcb);
Py_XDECREF(py_warningcb);
- Py_XDECREF(cbdata.py_pkgs);
+ Py_XDECREF(cbdata.py_pkg);
if (tmp_err) {
nice_exception(&tmp_err, NULL);
@@ -579,7 +572,7 @@ py_xml_parse_other_snippet(G_GNUC_UNUSED PyObject *self, PyObject *args)
cbdata.py_newpkgcb = py_newpkgcb;
cbdata.py_pkgcb = py_pkgcb;
cbdata.py_warningcb = py_warningcb;
- cbdata.py_pkgs = PyDict_New();
+ cbdata.py_pkg = NULL;
cr_xml_parse_other_snippet(target, ptr_c_newpkgcb, &cbdata, ptr_c_pkgcb, &cbdata,
ptr_c_warningcb, &cbdata, &tmp_err);
@@ -587,7 +580,7 @@ py_xml_parse_other_snippet(G_GNUC_UNUSED PyObject *self, PyObject *args)
Py_XDECREF(py_newpkgcb);
Py_XDECREF(py_pkgcb);
Py_XDECREF(py_warningcb);
- Py_XDECREF(cbdata.py_pkgs);
+ Py_XDECREF(cbdata.py_pkg);
if (tmp_err) {
nice_exception(&tmp_err, NULL);
@@ -630,7 +623,7 @@ py_xml_parse_repomd(G_GNUC_UNUSED PyObject *self, PyObject *args)
cbdata.py_newpkgcb = NULL;
cbdata.py_pkgcb = NULL;
cbdata.py_warningcb = py_warningcb;
- cbdata.py_pkgs = NULL;
+ cbdata.py_pkg = NULL;
repomd = Repomd_FromPyObject(py_repomd);
@@ -684,7 +677,7 @@ py_xml_parse_updateinfo(G_GNUC_UNUSED PyObject *self, PyObject *args)
cbdata.py_newpkgcb = NULL;
cbdata.py_pkgcb = NULL;
cbdata.py_warningcb = py_warningcb;
- cbdata.py_pkgs = NULL;
+ cbdata.py_pkg = NULL;
updateinfo = UpdateInfo_FromPyObject(py_updateinfo);
@@ -704,88 +697,3 @@ py_xml_parse_updateinfo(G_GNUC_UNUSED PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
-
-
-PyObject *
-py_xml_parse_main_metadata_together(G_GNUC_UNUSED PyObject *self, PyObject *args, PyObject *kwargs)
-{
- char *primary_filename;
- char *filelists_filename;
- char *other_filename;
- int allow_out_of_order = 1;
- PyObject *py_newpkgcb, *py_pkgcb, *py_warningcb;
- CbData cbdata;
- GError *tmp_err = NULL;
- static char *kwlist[] = { "primary", "filelists", "other", "newpkgcb", "pkgcb",
- "warningcb", "allow_out_of_order", NULL };
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sssOOO|p:py_xml_parse_main_metadata_together", kwlist,
- &primary_filename, &filelists_filename, &other_filename, &py_newpkgcb,
- &py_pkgcb, &py_warningcb, &allow_out_of_order)) {
- return NULL;
- }
-
- if (!PyCallable_Check(py_newpkgcb) && py_newpkgcb != Py_None) {
- PyErr_SetString(PyExc_TypeError, "newpkgcb must be callable or None");
- return NULL;
- }
-
- if (!PyCallable_Check(py_pkgcb) && py_pkgcb != Py_None) {
- PyErr_SetString(PyExc_TypeError, "pkgcb must be callable or None");
- return NULL;
- }
-
- if (!PyCallable_Check(py_warningcb) && py_warningcb != Py_None) {
- PyErr_SetString(PyExc_TypeError, "warningcb must be callable or None");
- return NULL;
- }
-
- if (py_newpkgcb == Py_None && py_pkgcb == Py_None) {
- PyErr_SetString(PyExc_ValueError, "both pkgcb and newpkgcb cannot be None");
- return NULL;
- }
-
- Py_XINCREF(py_newpkgcb);
- Py_XINCREF(py_pkgcb);
- Py_XINCREF(py_warningcb);
-
- cr_XmlParserNewPkgCb ptr_c_newpkgcb = NULL;
- cr_XmlParserPkgCb ptr_c_pkgcb = NULL;
- cr_XmlParserWarningCb ptr_c_warningcb = NULL;
-
- if (py_newpkgcb != Py_None)
- ptr_c_newpkgcb = c_newpkgcb;
- if (py_pkgcb != Py_None)
- ptr_c_pkgcb = c_pkgcb;
- if (py_warningcb != Py_None)
- ptr_c_warningcb = c_warningcb;
-
- cbdata.py_newpkgcb = py_newpkgcb;
- cbdata.py_pkgcb = py_pkgcb;
- cbdata.py_warningcb = py_warningcb;
- cbdata.py_pkgs = PyDict_New();
-
- cr_xml_parse_main_metadata_together(primary_filename,
- filelists_filename,
- other_filename,
- ptr_c_newpkgcb,
- &cbdata,
- ptr_c_pkgcb,
- &cbdata,
- ptr_c_warningcb,
- &cbdata,
- allow_out_of_order,
- &tmp_err);
-
- Py_XDECREF(py_newpkgcb);
- Py_XDECREF(py_pkgcb);
- Py_XDECREF(py_warningcb);
- Py_XDECREF(cbdata.py_pkgs);
-
- if (tmp_err) {
- nice_exception(&tmp_err, NULL);
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
diff --git a/src/python/xml_parser-py.h b/src/python/xml_parser-py.h
index 3260005..e5eea9f 100644
--- a/src/python/xml_parser-py.h
+++ b/src/python/xml_parser-py.h
@@ -64,12 +64,4 @@ PyDoc_STRVAR(xml_parse_updateinfo__doc__,
PyObject *py_xml_parse_updateinfo(PyObject *self, PyObject *args);
-PyDoc_STRVAR(xml_parse_main_metadata_together__doc__,
-"xml_parse_main_metadata_together(primary_filename, filelists_filename, other_filename, newpkgcb, pkgcb, warningcb) -> None\n\n"
-"Parse primary.xml, filelists.xml and other.xml together at the same time."
-"- It can handle if packages are not in the same order in all 3 files but memory requirements grow."
-"- It is not guaranteed that newpkgcb is always followed by pkgcb for the given package, it is possible newpkgcb will be called several times for different packages and only after that pkgcbs will be called.");
-
-PyObject *py_xml_parse_main_metadata_together(PyObject *self, PyObject *args, PyObject *kwargs);
-
#endif