Python: Add function xml_dump_updaterecord()
authorTomas Mlcoch <tmlcoch@redhat.com>
Mon, 4 Aug 2014 16:01:30 +0000 (18:01 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Mon, 4 Aug 2014 16:01:30 +0000 (18:01 +0200)
src/python/__init__.py
src/python/createrepo_cmodule.c
src/python/xml_dump-py.c
src/python/xml_dump-py.h
src/xml_dump.h
src/xml_dump_updateinfo.c
tests/python/tests/test_updaterecord.py

index 46af641..f231156 100644 (file)
@@ -257,10 +257,11 @@ def xml_from_rpm(filename, checksum_type=SHA256, location_href=None,
     return _createrepo_c.xml_from_rpm(filename, checksum_type,
                       location_href, location_base, changelog_limit)
 
-xml_dump_primary    = _createrepo_c.xml_dump_primary
-xml_dump_filelists  = _createrepo_c.xml_dump_filelists
-xml_dump_other      = _createrepo_c.xml_dump_other
-xml_dump            = _createrepo_c.xml_dump
+xml_dump_primary        = _createrepo_c.xml_dump_primary
+xml_dump_filelists      = _createrepo_c.xml_dump_filelists
+xml_dump_other          =  _createrepo_c.xml_dump_other
+xml_dump_updaterecord   = _createrepo_c.xml_dump_updaterecord
+xml_dump                = _createrepo_c.xml_dump
 
 def xml_parse_primary(path, newpkgcb=None, pkgcb=None,
                       warningcb=None, do_files=1):
index e7a02af..9489b11 100644 (file)
@@ -53,6 +53,8 @@ static struct PyMethodDef createrepo_c_methods[] = {
         METH_VARARGS, xml_dump_filelists__doc__},
     {"xml_dump_other",          (PyCFunction)py_xml_dump_other,
         METH_VARARGS, xml_dump_other__doc__},
+    {"xml_dump_updaterecord",    (PyCFunction)py_xml_dump_updaterecord,
+        METH_VARARGS, xml_dump_updaterecord__doc__},
     {"xml_dump",                (PyCFunction)py_xml_dump,
         METH_VARARGS, xml_dump__doc__},
     {"xml_parse_primary",       (PyCFunction)py_xml_parse_primary,
index e024e67..a74eaf9 100644 (file)
@@ -26,6 +26,7 @@
 #include "typeconversion.h"
 #include "package-py.h"
 #include "exception-py.h"
+#include "updaterecord-py.h"
 
 PyObject *
 py_xml_dump_primary(PyObject *self, PyObject *args)
@@ -132,3 +133,27 @@ py_xml_dump(PyObject *self, PyObject *args)
 
     return tuple;
 }
+
+PyObject *
+py_xml_dump_updaterecord(PyObject *self, PyObject *args)
+{
+    PyObject *py_rec, *py_str;
+    char *xml;
+    GError *err = NULL;
+
+    CR_UNUSED(self);
+
+    if (!PyArg_ParseTuple(args, "O!:py_xml_dump_updaterecord",
+                          &UpdateRecord_Type, &py_rec))
+        return NULL;
+
+    xml = cr_xml_dump_updaterecord(UpdateRecord_FromPyObject(py_rec), &err);
+    if (err) {
+        nice_exception(&err, NULL);
+        return NULL;
+    }
+
+    py_str = PyStringOrNone_FromString(xml);
+    free(xml);
+    return py_str;
+}
index 8699e3a..042c97b 100644 (file)
@@ -46,4 +46,10 @@ PyDoc_STRVAR(xml_dump__doc__,
 
 PyObject *py_xml_dump(PyObject *self, PyObject *args);
 
+PyDoc_STRVAR(xml_dump_updaterecord__doc__,
+"xml_dump_updaterecord(pkg) -> str\n\n"
+"Generate xml chunk from UpdateRecord");
+
+PyObject *py_xml_dump_updaterecord(PyObject *self, PyObject *args);
+
 #endif
index 5833d3d..810a39e 100644 (file)
@@ -137,7 +137,7 @@ char *cr_xml_dump_updateinfo(cr_UpdateInfo *updateinfo, GError **err);
  * @param err           **GError
  * @return              xml chunk string or NULL on error
  */
-char *cr_xml_dump_updateinforecord(cr_UpdateRecord *rec, GError **err);
+char *cr_xml_dump_updaterecord(cr_UpdateRecord *rec, GError **err);
 
 /** Generate xml representation of cr_DeltaPackage
  * @param dpkg          cr_DeltaPackage
index 43b93ea..1bfb923 100644 (file)
@@ -192,7 +192,7 @@ cr_xml_dump_updateinfo(cr_UpdateInfo *updateinfo, GError **err)
 }
 
 char *
-cr_xml_dump_updateinforecord(cr_UpdateRecord *rec, GError **err)
+cr_xml_dump_updaterecord(cr_UpdateRecord *rec, GError **err)
 {
     xmlNodePtr root;
     char *result;
index faf1869..ebcfede 100644 (file)
@@ -87,3 +87,41 @@ class TestCaseUpdateRecord(unittest.TestCase):
         self.assertEqual(col.name, "long name")
         self.assertEqual(len(col.packages), 0)
 
+    def test_xml_dump_updaterecord(self):
+        rec = cr.UpdateRecord()
+        rec.fromstr = "from"
+        rec.status = "status"
+        rec.type = "type"
+        rec.version = "version"
+        rec.id = "id"
+        rec.title = "title"
+        rec.issued_date = "issued_date"
+        rec.updated_date = "updated_date"
+        rec.rights = "rights"
+        rec.release = "release"
+        rec.pushcount = "pushcount"
+        rec.severity = "severity"
+        rec.summary = "summary"
+        rec.description = "description"
+        rec.solution = "solution"
+
+        xml = cr.xml_dump_updaterecord(rec)
+        self.assertEqual(xml,
+"""    <delta>
+      <update from="from" status="status" type="type" version="version">
+        <id>id</id>
+        <title>title</title>
+        <issued date="issued_date"/>
+        <updated date="updated_date"/>
+        <rights>rights</rights>
+        <release>release</release>
+        <pushcount>pushcount</pushcount>
+        <severity>severity</severity>
+        <summary>summary</summary>
+        <description>description</description>
+        <solution>solution</solution>
+        <references/>
+        <pkglist/>
+      </update>
+    </delta>
+""")