pytdb: Update open flags to match those for tdb_open() in tdb.h
[metze/ctdb/wip.git] / lib / tdb / pytdb.c
index 60aae9fd867899532852af89ad44f8c9805d2345..e50615f4b1a123fa4963c9ff5f455c3c6905df1b 100644 (file)
@@ -1,7 +1,7 @@
 /* 
    Unix SMB/CIFS implementation.
 
-   Swig interface to tdb.
+   Python interface to tdb.
 
    Copyright (C) 2004-2006 Tim Potter <tpot@samba.org>
    Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
 #endif
 
-#ifdef HAVE_FSTAT
-#undef HAVE_FSTAT
-#endif
-
 /* Include tdb headers */
 #include <tdb.h>
 
@@ -116,13 +112,6 @@ static PyObject *obj_transaction_commit(PyTdbObject *self)
        Py_RETURN_NONE;
 }
 
-static PyObject *obj_transaction_recover(PyTdbObject *self)
-{
-       int ret = tdb_transaction_recover(self->ctx);
-       PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
-       Py_RETURN_NONE;
-}
-
 static PyObject *obj_transaction_start(PyTdbObject *self)
 {
        int ret = tdb_transaction_start(self->ctx);
@@ -270,6 +259,27 @@ static PyObject *obj_store(PyTdbObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
+static PyObject *obj_add_flags(PyTdbObject *self, PyObject *args)
+{
+       unsigned flags;
+
+       if (!PyArg_ParseTuple(args, "I", &flags))
+               return NULL;
+
+       tdb_add_flags(self->ctx, flags);
+       Py_RETURN_NONE;
+}
+
+static PyObject *obj_remove_flags(PyTdbObject *self, PyObject *args)
+{
+       unsigned flags;
+
+       if (!PyArg_ParseTuple(args, "I", &flags))
+               return NULL;
+
+       tdb_remove_flags(self->ctx, flags);
+       Py_RETURN_NONE;
+}
 
 typedef struct {
        PyObject_HEAD
@@ -329,9 +339,6 @@ static PyMethodDef tdb_object_methods[] = {
        { "transaction_commit", (PyCFunction)obj_transaction_commit, METH_NOARGS,
                "S.transaction_commit() -> None\n"
                "Commit the currently active transaction." },
-       { "transaction_recover", (PyCFunction)obj_transaction_recover, METH_NOARGS,
-               "S.transaction_recover() -> None\n"
-               "Recover the currently active transaction." },
        { "transaction_start", (PyCFunction)obj_transaction_start, METH_NOARGS,
                "S.transaction_start() -> None\n"
                "Start a new transaction." },
@@ -341,7 +348,7 @@ static PyMethodDef tdb_object_methods[] = {
        { "read_lock_all", (PyCFunction)obj_lockall_read, METH_NOARGS, NULL },
        { "read_unlock_all", (PyCFunction)obj_unlockall_read, METH_NOARGS, NULL },
        { "close", (PyCFunction)obj_close, METH_NOARGS, NULL },
-       { "get", (PyCFunction)obj_get, METH_VARARGS, "S.fetch(key) -> value\n"
+       { "get", (PyCFunction)obj_get, METH_VARARGS, "S.get(key) -> value\n"
                "Fetch a value." },
        { "append", (PyCFunction)obj_append, METH_VARARGS, "S.append(key, value) -> None\n"
                "Append data to an existing key." },
@@ -355,6 +362,8 @@ static PyMethodDef tdb_object_methods[] = {
                "Check whether key exists in this database." },
        { "store", (PyCFunction)obj_store, METH_VARARGS, "S.store(key, data, flag=REPLACE) -> None"
                "Store data." },
+       { "add_flags", (PyCFunction)obj_add_flags, METH_VARARGS, "S.add_flags(flags) -> None" },
+       { "remove_flags", (PyCFunction)obj_remove_flags, METH_VARARGS, "S.remove_flags(flags) -> None" },
        { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" },
        { "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n"
                "Wipe the entire database." },
@@ -400,7 +409,9 @@ static PyGetSetDef tdb_object_getsetters[] = {
 
 static PyObject *tdb_object_repr(PyTdbObject *self)
 {
-       return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx));
+       return PyString_FromFormat("Tdb('%s')",
+               (tdb_get_flags(self->ctx) & TDB_INTERNAL) ? "<internal>"
+                                                         : tdb_name(self->ctx));
 }
 
 static void tdb_object_dealloc(PyTdbObject *self)
@@ -511,6 +522,12 @@ void inittdb(void)
        PyModule_AddObject(m, "NOMMAP", PyInt_FromLong(TDB_NOMMAP));
        PyModule_AddObject(m, "CONVERT", PyInt_FromLong(TDB_CONVERT));
        PyModule_AddObject(m, "BIGENDIAN", PyInt_FromLong(TDB_BIGENDIAN));
+       PyModule_AddObject(m, "NOSYNC", PyInt_FromLong(TDB_NOSYNC));
+       PyModule_AddObject(m, "SEQNUM", PyInt_FromLong(TDB_SEQNUM));
+       PyModule_AddObject(m, "VOLATILE", PyInt_FromLong(TDB_VOLATILE));
+       PyModule_AddObject(m, "ALLOW_NESTING", PyInt_FromLong(TDB_ALLOW_NESTING));
+       PyModule_AddObject(m, "DISALLOW_NESTING", PyInt_FromLong(TDB_DISALLOW_NESTING));
+
        PyModule_AddObject(m, "__docformat__", PyString_FromString("restructuredText"));
 
        Py_INCREF(&PyTdb);