pytdb: Add support for tdb_repack()
authorKirill Smelkov <kirr@mns.spb.ru>
Sat, 2 Oct 2010 13:43:46 +0000 (17:43 +0400)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 7 Oct 2010 04:48:27 +0000 (15:18 +1030)
Cc: 597386@bugs.debian.org
Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
lib/tdb/pytdb.c
lib/tdb/python/tests/simple.py

index c2ba661369233a4e297d67bf3051da4b573a186b..402fa5d9d3a0f674cb65ad6762b6661d3fd338c5 100644 (file)
@@ -343,6 +343,13 @@ static PyObject *obj_clear(PyTdbObject *self)
        Py_RETURN_NONE;
 }
 
+static PyObject *obj_repack(PyTdbObject *self)
+{
+       int ret = tdb_repack(self->ctx);
+       PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
+       Py_RETURN_NONE;
+}
+
 static PyObject *obj_enable_seqnum(PyTdbObject *self)
 {
        tdb_enable_seqnum(self->ctx);
@@ -393,6 +400,8 @@ static PyMethodDef tdb_object_methods[] = {
        { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" },
        { "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n"
                "Wipe the entire database." },
+       { "repack", (PyCFunction)obj_repack, METH_NOARGS, "S.repack() -> None\n"
+               "Repack the entire database." },
        { "enable_seqnum", (PyCFunction)obj_enable_seqnum, METH_NOARGS,
                "S.enable_seqnum() -> None" },
        { "increment_seqnum_nonblock", (PyCFunction)obj_increment_seqnum_nonblock, METH_NOARGS,
index b7eb0b5e5a076db075c10f24b5643f82c62312fd..92244e3ad2ec79aabd69f9800d2cdd80169425c7 100644 (file)
@@ -137,6 +137,12 @@ class SimpleTdbTests(TestCase):
         self.tdb.clear()
         self.assertEquals(0, len(list(self.tdb)))
 
+    def test_repack(self):
+        self.tdb["foo"] = "abc"
+        self.tdb["bar"] = "def"
+        del self.tdb["foo"]
+        self.tdb.repack()
+
     def test_seqnum(self):
         self.tdb.enable_seqnum()
         seq1 = self.tdb.seqnum