python: Add createrepo_c.compression_type() function.
authorTomas Mlcoch <tmlcoch@redhat.com>
Thu, 10 Oct 2013 10:56:04 +0000 (12:56 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Thu, 10 Oct 2013 10:56:04 +0000 (12:56 +0200)
src/python/__init__.py
src/python/compression_wrapper-py.c
src/python/compression_wrapper-py.h
src/python/createrepo_cmodule.c
tests/python/tests/test_compression_wrapper.py

index b9b0f749c2c0cc38786ee0b3a7ff9606cd1105ea..27518630f0037eacf7d688bd8a9db18258d8cb39 100644 (file)
@@ -252,3 +252,4 @@ def compress_file(src, dst, comtype, stat=None):
 
 compression_suffix  = _createrepo_c.compression_suffix
 detect_compression  = _createrepo_c.detect_compression
+compression_type    = _createrepo_c.compression_type
index 1fdad4115326dd2b575d08b3c21e432c5e2e2575..988766bf53e8595f68dceb1bc4fcca036b9a6793 100644 (file)
@@ -64,6 +64,19 @@ py_detect_compression(PyObject *self, PyObject *args)
     return PyLong_FromLong(type);
 }
 
+PyObject *
+py_compression_type(PyObject *self, PyObject *args)
+{
+    char *name;
+
+    CR_UNUSED(self);
+
+    if (!PyArg_ParseTuple(args, "z:py_compression_type", &name))
+        return NULL;
+
+    return PyLong_FromLong((long) cr_compression_type(name));
+}
+
 /*
  * CrFile object
  */
index 6dbc7e52d94746e6397d578be0f229b75713a451..e6598978cc54ebae170ab7d1fb20d59bffb7edc6 100644 (file)
@@ -38,4 +38,11 @@ PyDoc_STRVAR(detect_compression__doc__,
 
 PyObject *py_detect_compression(PyObject *self, PyObject *args);
 
+PyDoc_STRVAR(compression_type__doc__,
+"compression_type(string) -> int\n\n"
+"Compression type value");
+
+PyObject *py_compression_type(PyObject *self, PyObject *args);
+
+
 #endif
index 0691d3f31660f201565e2a75ce79601d425fcd5d..4cb019c600097896af84b238fe892d8f0d5b8a73 100644 (file)
@@ -68,6 +68,8 @@ static struct PyMethodDef createrepo_c_methods[] = {
         METH_VARARGS, compression_suffix__doc__},
     {"detect_compression",      (PyCFunction)py_detect_compression,
         METH_VARARGS, detect_compression__doc__},
+    {"compression_type",        (PyCFunction)py_compression_type,
+        METH_VARARGS, compression_type__doc__},
     { NULL }
 };
 
index d19569c1dd02251fc53cf31a5bc9d9c03e385a1b..1e889c53bd620b9cc33e07481409d45a1029aa6a 100644 (file)
@@ -57,3 +57,10 @@ class TestCaseCompressionWrapper(unittest.TestCase):
         comtype = cr.detect_compression(path)
         self.assertEqual(comtype, cr.XZ)
 
+    def test_compression_type(self):
+        self.assertEqual(cr.compression_type(None), cr.UNKNOWN_COMPRESSION)
+        self.assertEqual(cr.compression_type(""), cr.UNKNOWN_COMPRESSION)
+        self.assertEqual(cr.compression_type("gz"), cr.GZ)
+        self.assertEqual(cr.compression_type("bz2"), cr.BZ2)
+        self.assertEqual(cr.compression_type("xz"), cr.XZ)
+        self.assertEqual(cr.compression_type("XZ"), cr.XZ)