FILE(COPY ${createrepo_c_COPIES} DESTINATION ./createrepo_c/)
SET (craeterepo_cmodule_SRCS
+ checksum-py.c
contentstat-py.c
createrepo_cmodule.c
exception-py.c
def xml_parse_repomd(path, repomdobj, warning_cb=None):
return _createrepo_c.xml_parse_repomd(path, repomdobj, warning_cb)
+
+checksum_name_str = _createrepo_c.checksum_name_str
+checksum_type = _createrepo_c.checksum_type
--- /dev/null
+/* createrepo_c - Library of routines for manipulation with repodata
+ * Copyright (C) 2013 Tomas Mlcoch
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+#include <Python.h>
+#include <assert.h>
+#include <stddef.h>
+
+#include "src/createrepo_c.h"
+
+#include "typeconversion.h"
+#include "exception-py.h"
+
+PyObject *
+py_checksum_name_str(PyObject *self, PyObject *args)
+{
+ int type;
+
+ CR_UNUSED(self);
+
+ if (!PyArg_ParseTuple(args, "i:py_checksum_name_Str", &type))
+ return NULL;
+
+ return PyStringOrNone_FromString(cr_checksum_name_str(type));
+}
+
+PyObject *
+py_checksum_type(PyObject *self, PyObject *args)
+{
+ char *type;
+
+ CR_UNUSED(self);
+
+ if (!PyArg_ParseTuple(args, "s:py_checksum_type", &type))
+ return NULL;
+
+ return PyLong_FromLong((long) cr_checksum_type(type));
+}
--- /dev/null
+/* createrepo_c - Library of routines for manipulation with repodata
+ * Copyright (C) 2013 Tomas Mlcoch
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+#ifndef CR_CHECKSUM_PY_H
+#define CR_CHECKSUM_PY_H
+
+#include "src/createrepo_c.h"
+
+PyObject *py_checksum_name_str(PyObject *self, PyObject *args);
+PyObject *py_checksum_type(PyObject *self, PyObject *args);
+
+#endif
#include "src/createrepo_c.h"
+#include "checksum-py.h"
#include "contentstat-py.h"
#include "exception-py.h"
#include "load_metadata-py.h"
METH_VARARGS, NULL},
{"xml_parse_repomd", (PyCFunction)py_xml_parse_repomd,
METH_VARARGS, NULL},
+ {"checksum_name_str", (PyCFunction)py_checksum_name_str,
+ METH_VARARGS, NULL},
+ {"checksum_type", (PyCFunction)py_checksum_type,
+ METH_VARARGS, NULL},
{ NULL }
};
--- /dev/null
+import unittest
+import shutil
+import tempfile
+import os.path
+import createrepo_c as cr
+
+from fixtures import *
+
+class TestCaseChecksum(unittest.TestCase):
+
+ def test_checksum_name_str(self):
+ self.assertEqual(cr.checksum_name_str(cr.MD5), "md5")
+ self.assertEqual(cr.checksum_name_str(cr.SHA), "sha")
+ self.assertEqual(cr.checksum_name_str(cr.SHA1), "sha1")
+ self.assertEqual(cr.checksum_name_str(cr.SHA224), "sha224")
+ self.assertEqual(cr.checksum_name_str(cr.SHA256), "sha256")
+ self.assertEqual(cr.checksum_name_str(cr.SHA384), "sha384")
+ self.assertEqual(cr.checksum_name_str(cr.SHA512), "sha512")
+ self.assertEqual(cr.checksum_name_str(65), None)
+
+ def test_checksum_type(self):
+ self.assertEqual(cr.checksum_type("sha256"), cr.SHA256)
+ self.assertEqual(cr.checksum_type("SHA256"), cr.SHA256)
+ self.assertEqual(cr.checksum_type("Sha256"), cr.SHA256)
+ self.assertEqual(cr.checksum_type("sHa256"), cr.SHA256)
+ self.assertEqual(cr.checksum_type("ShA256"), cr.SHA256)
+
+ self.assertEqual(cr.checksum_type("md5"), cr.MD5)
+ self.assertEqual(cr.checksum_type("sha"), cr.SHA)
+ self.assertEqual(cr.checksum_type("sha1"), cr.SHA1)
+ self.assertEqual(cr.checksum_type("sha224"), cr.SHA224)
+ self.assertEqual(cr.checksum_type("sha256"), cr.SHA256)
+ self.assertEqual(cr.checksum_type("sha384"), cr.SHA384)
+ self.assertEqual(cr.checksum_type("sha512"), cr.SHA512)
+