pydsdb: Move dsdb_set_schema_from_ldb to pydsdb.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 19 Jun 2010 15:09:52 +0000 (17:09 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 19 Jun 2010 20:46:43 +0000 (22:46 +0200)
source4/dsdb/pydsdb.c
source4/scripting/python/pyglue.c
source4/scripting/python/samba/__init__.py

index ce7923ddadc936ae28c358d2c3f68286973ec0e9..8f9ed9fa77baf6dd1e01bc855af0c2104cc16f57 100644 (file)
@@ -408,6 +408,35 @@ static PyObject *py_dsdb_set_schema_from_ldif(PyObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
+static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb;
+       struct ldb_context *ldb;
+       PyObject *py_from_ldb;
+       struct ldb_context *from_ldb;
+       struct dsdb_schema *schema;
+       int ret;
+       if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_from_ldb))
+               return NULL;
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       PyErr_LDB_OR_RAISE(py_from_ldb, from_ldb);
+
+       schema = dsdb_get_schema(from_ldb, NULL);
+       if (!schema) {
+               PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on 'from' ldb!\n");
+               return NULL;
+       }
+
+       ret = dsdb_reference_schema(ldb, schema, true);
+       PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
+
+       Py_RETURN_NONE;
+}
+
+
+
 static PyMethodDef py_dsdb_methods[] = {
        { "samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
                METH_VARARGS, "Get the server site name as a string"},
@@ -446,6 +475,8 @@ static PyMethodDef py_dsdb_methods[] = {
                NULL },
        { "dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
                NULL },
+       { "dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
+               NULL },
        { NULL }
 };
 
index 8dc80505d6187a255f9ae515c2e99a8131a70eb5..ce164a708569ce9094547824e073d6bf9f125b9e 100644 (file)
        } */\
        ldb = PyLdb_AsLdbContext(py_ldb);
 
-static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
-{
-       if (ret == LDB_ERR_PYTHON_EXCEPTION)
-               return; /* Python exception should already be set, just keep that */
-
-       PyErr_SetObject(error, 
-                       Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
-                       ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
-}
-
-static PyObject *py_ldb_get_exception(void)
-{
-       PyObject *mod = PyImport_ImportModule("ldb");
-       if (mod == NULL)
-               return NULL;
-
-       return PyObject_GetAttrString(mod, "LdbError");
-}
-
 static PyObject *py_generate_random_str(PyObject *self, PyObject *args)
 {
        int len;
@@ -174,33 +155,6 @@ static PyObject *py_dsdb_write_prefixes_from_schema_to_ldb(PyObject *self, PyObj
        Py_RETURN_NONE;
 }
 
-static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
-{
-       PyObject *py_ldb;
-       struct ldb_context *ldb;
-       PyObject *py_from_ldb;
-       struct ldb_context *from_ldb;
-       struct dsdb_schema *schema;
-       int ret;
-       if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_from_ldb))
-               return NULL;
-
-       PyErr_LDB_OR_RAISE(py_ldb, ldb);
-
-       PyErr_LDB_OR_RAISE(py_from_ldb, from_ldb);
-
-       schema = dsdb_get_schema(from_ldb, NULL);
-       if (!schema) {
-               PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on 'from' ldb!\n");
-               return NULL;
-       }
-
-       ret = dsdb_reference_schema(ldb, schema, true);
-       PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
-
-       Py_RETURN_NONE;
-}
-
 /*
   return the list of interface IPs we have configured
   takes an loadparm context, returns a list of IPs in string form
@@ -270,8 +224,6 @@ static PyMethodDef py_misc_methods[] = {
                "nttime2string(nttime) -> string" },
        { "dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, METH_VARARGS,
                NULL },
-       { "dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
-               NULL },
        { "set_debug_level", (PyCFunction)py_set_debug_level, METH_VARARGS,
                "set debug level" },
        { "interface_ips", (PyCFunction)py_interface_ips, METH_VARARGS,
index d03cdc13a59bbf49531e063fb324a97dcdd69145..2f125e6ba76dd5f3ac23ce2e2c5f9943a5c23529 100644 (file)
@@ -284,7 +284,7 @@ class Ldb(_Ldb):
         return dsdb.dsdb_get_oid_from_attid(self, attid)
 
     def set_schema_from_ldb(self, ldb):
-        _glue.dsdb_set_schema_from_ldb(self, ldb)
+        dsdb.dsdb_set_schema_from_ldb(self, ldb)
 
     def write_prefixes_from_schema(self):
         _glue.dsdb_write_prefixes_from_schema_to_ldb(self)