exception-py.c
load_metadata-py.c
locate_metadata-py.c
+ misc-py.c
package-py.c
parsepkg-py.c
repomd-py.c
checksum_name_str = _createrepo_c.checksum_name_str
checksum_type = _createrepo_c.checksum_type
+
+def compress_file(src, dst, comtype, stat=None):
+ return _createrepo_c.compress_file(src, dst, comtype, stat)
#include "exception-py.h"
#include "load_metadata-py.h"
#include "locate_metadata-py.h"
+#include "misc-py.h"
#include "package-py.h"
#include "parsepkg-py.h"
#include "repomd-py.h"
METH_VARARGS, NULL},
{"checksum_type", (PyCFunction)py_checksum_type,
METH_VARARGS, NULL},
+ {"compress_file", (PyCFunction)py_compress_file_with_stat,
+ METH_VARARGS, NULL},
{ NULL }
};
--- /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"
+#include "misc-py.h"
+#include "contentstat-py.h"
+
+PyObject *
+py_compress_file_with_stat(PyObject *self, PyObject *args)
+{
+ int type;
+ char *src, *dst;
+ PyObject *py_contentstat = NULL;
+ cr_ContentStat *contentstat;
+ GError *tmp_err = NULL;
+
+ CR_UNUSED(self);
+
+ if (!PyArg_ParseTuple(args, "sziO:py_compress_file", &src, &dst, &type,
+ &py_contentstat))
+ return NULL;
+
+ if (!py_contentstat || py_contentstat == Py_None) {
+ contentstat = NULL;
+ } else {
+ contentstat = ContentStat_FromPyObject(py_contentstat);
+ if (!contentstat)
+ return NULL;
+ }
+
+ cr_compress_file_with_stat(src, dst, type, contentstat, &tmp_err);
+ if (tmp_err) {
+ PyErr_SetString(CrErr_Exception, tmp_err->message);
+ g_clear_error(&tmp_err);
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
--- /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_MISC_PY_H
+#define CR_MISC_PY_H
+
+#include "src/createrepo_c.h"
+
+PyObject *py_compress_file_with_stat(PyObject *self, PyObject *args);
+
+#endif
--- /dev/null
+import os.path
+import tempfile
+import unittest
+import shutil
+import createrepo_c as cr
+
+from fixtures import *
+
+class TestCaseMisc(unittest.TestCase):
+
+ def setUp(self):
+ self.tmpdir = tempfile.mkdtemp(prefix="createrepo_ctest-")
+ self.nofile = os.path.join(self.tmpdir, "this_file_should_not_exists")
+ self.tmpfile = os.path.join(self.tmpdir, "file")
+ self.content = "some\nfoo\ncontent\n"
+ open(self.tmpfile, "w").write(self.content)
+
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
+ def test_compress_file(self):
+ # Non exist file
+ self.assertRaises(cr.CreaterepoCError, cr.compress_file,
+ self.nofile, None, cr.BZ2)
+
+ # Compression - use the same name+suffix
+ cr.compress_file(self.tmpfile, None, cr.BZ2)
+ self.assertTrue(os.path.isfile(self.tmpfile+".bz2"))
+
+ # Compression - new name
+ new_name = os.path.join(self.tmpdir, "foobar.gz")
+ cr.compress_file(self.tmpfile, new_name, cr.GZ)
+ self.assertTrue(os.path.isfile(new_name))
+
+ # Compression - with stat
+ stat = cr.ContentStat(cr.SHA256)
+ cr.compress_file(self.tmpfile, None, cr.XZ, stat)
+ self.assertTrue(os.path.isfile(self.tmpfile+".xz"))
+ self.assertEqual(stat.checksum, "e61ebaa6241e335c779194ce7af98c590f1"\
+ "b26a749f219b997a0d7d5a773063b")
+ self.assertEqual(stat.checksum_type, cr.SHA256)
+ self.assertEqual(stat.size, len(self.content))
+
+ # Check directory for unexpected files
+ self.assertEqual(set(os.listdir(self.tmpdir)),
+ set(['file.bz2', 'file.xz', 'file', 'foobar.gz']))
+