Author: jelmer Date: 2007-11-19 19:28:19 +0000 (Mon, 19 Nov 2007) New Revision: 26041
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=26041 Log: Some more cleanups, support setting the debug function for ldb from python. Modified: branches/4.0-python/ branches/4.0-python/source/BRANCH.TODO branches/4.0-python/source/lib/ldb/ldb.i branches/4.0-python/source/lib/ldb/tests/python/api.py branches/4.0-python/source/lib/registry/registry.i branches/4.0-python/source/scripting/python/miscmodule.c branches/4.0-python/source/scripting/python/samba/__init__.py branches/4.0-python/source/scripting/python/samba/provision.py branches/4.0-python/source/scripting/python/sidmodule.c branches/4.0-python/source/scripting/python/uuidmodule.c branches/4.0-python/source/setup/provision Changeset: Property changes on: branches/4.0-python ___________________________________________________________________ Name: bzr:revision-info ...skipped... Name: bzr:file-ids ...skipped... Name: bzr:revision-id:v3-trunk0 ...skipped... Modified: branches/4.0-python/source/BRANCH.TODO =================================================================== --- branches/4.0-python/source/BRANCH.TODO 2007-11-19 18:20:55 UTC (rev 26040) +++ branches/4.0-python/source/BRANCH.TODO 2007-11-19 19:28:19 UTC (rev 26041) @@ -2,3 +2,4 @@ - make sure exceptions are properly thrown everywhere - Use LdbError, NtStatusError, WinError rather than RuntimeError - fix web server +- allow non-top-level modules in build system Modified: branches/4.0-python/source/lib/ldb/ldb.i =================================================================== --- branches/4.0-python/source/lib/ldb/ldb.i 2007-11-19 18:20:55 UTC (rev 26040) +++ branches/4.0-python/source/lib/ldb/ldb.i 2007-11-19 19:28:19 UTC (rev 26041) @@ -392,6 +392,26 @@ typedef struct ldb_ldif ldb_ldif; +#ifdef SWIGPYTHON +%{ +static void py_ldb_debug(void *context, enum ldb_debug_level level, const char *fmt, va_list ap) +{ + char *text; + PyObject *fn = context; + + vasprintf(&text, fmt, ap); + PyObject_CallFunction(fn, "(i,s)", level, text); + free(text); +} +%} + +%typemap(in) (void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), + void *context) { + $1 = py_ldb_debug; + $2 = $input; +} +#endif + %inline { static PyObject *ldb_ldif_to_pyobject(ldb_ldif *ldif) { @@ -457,6 +477,9 @@ const char *errstring(); void set_create_perms(unsigned int perms); void set_modules_dir(const char *path); + ldb_error set_debug(void (*debug)(void *context, enum ldb_debug_level level, + const char *fmt, va_list ap), + void *context); ldb_error transaction_start(); ldb_error transaction_commit(); ldb_error transaction_cancel(); Modified: branches/4.0-python/source/lib/ldb/tests/python/api.py =================================================================== --- branches/4.0-python/source/lib/ldb/tests/python/api.py 2007-11-19 18:20:55 UTC (rev 26040) +++ branches/4.0-python/source/lib/ldb/tests/python/api.py 2007-11-19 19:28:19 UTC (rev 26041) @@ -13,6 +13,7 @@ self.assertTrue(ldb.valid_attr_name("foo")) self.assertFalse(ldb.valid_attr_name("24foo")) + class SimpleLdb(unittest.TestCase): def test_connect(self): ldb.Ldb("foo.tdb") @@ -184,7 +185,13 @@ l.transaction_cancel() self.assertEquals(0, len(l.search(ldb.Dn(l, "dc=foo")))) + def test_set_debug(self): + def my_report_fn(level, text): + pass + l = ldb.Ldb("foo.tdb") + l.set_debug(my_report_fn) + class DnTests(unittest.TestCase): def setUp(self): self.ldb = ldb.Ldb("foo.tdb") Modified: branches/4.0-python/source/lib/registry/registry.i =================================================================== --- branches/4.0-python/source/lib/registry/registry.i 2007-11-19 18:20:55 UTC (rev 26040) +++ branches/4.0-python/source/lib/registry/registry.i 2007-11-19 19:28:19 UTC (rev 26041) @@ -51,7 +51,6 @@ } %typemap(argout) struct registry_context ** { - Py_XDECREF($result); $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_registry_context, 0); } Modified: branches/4.0-python/source/scripting/python/miscmodule.c =================================================================== --- branches/4.0-python/source/scripting/python/miscmodule.c 2007-11-19 18:20:55 UTC (rev 26040) +++ branches/4.0-python/source/scripting/python/miscmodule.c 2007-11-19 19:28:19 UTC (rev 26041) @@ -29,7 +29,7 @@ if (!PyArg_ParseTuple(args, "d", &length)) return NULL; - str = generate_random_str(PyMemCtx(), length); + str = generate_random_str(NULL, length); if (str == NULL) { PyErr_SetString(PyExc_TypeError, "can't generate random password"); @@ -41,7 +41,6 @@ static PyObject *py_nttime(PyObject *self, PyObject *args) { - char *str; struct timeval tv = timeval_current(); if (!PyArg_ParseTuple(args, "")) Modified: branches/4.0-python/source/scripting/python/samba/__init__.py =================================================================== --- branches/4.0-python/source/scripting/python/samba/__init__.py 2007-11-19 18:20:55 UTC (rev 26040) +++ branches/4.0-python/source/scripting/python/samba/__init__.py 2007-11-19 19:28:19 UTC (rev 26041) @@ -32,6 +32,9 @@ if modules_dir is None: modules_dir = os.path.join(os.getcwd(), "bin", "modules", "ldb") ret.set_modules_dir(modules_dir) + def samba_debug(level,text): + print "%d %s\n" % (level, text) + ret.set_debug(samba_debug) ret.connect(url) return ret Modified: branches/4.0-python/source/scripting/python/samba/provision.py =================================================================== --- branches/4.0-python/source/scripting/python/samba/provision.py 2007-11-19 18:20:55 UTC (rev 26040) +++ branches/4.0-python/source/scripting/python/samba/provision.py 2007-11-19 19:28:19 UTC (rev 26041) @@ -12,9 +12,11 @@ import uuid, sid, misc from socket import gethostname, gethostbyname import param +import registry from samba import Ldb, substitute_var from ldb import Dn, SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE + class InvalidNetbiosName(Exception): def __init__(self, name): super(InvalidNetbiosName, self).__init__("The name '%r' is not a valid NetBIOS name" % name) @@ -324,6 +326,7 @@ for (changetype, msg) in ldb.parse_ldif(data): ldb.modify(msg) + def setup_file(setup_dir, template, message, fname, subobj): """Setup a file in the private dir.""" f = fname @@ -465,10 +468,10 @@ setup_ldb(setup_dir, "secrets.ldif", session_info, credentials, subobj, paths.secrets, False) message("Setting up registry") - import registry reg = registry.Registry() - reg.mount(paths.hklm, registry.HKEY_LOCAL_MACHINE, []) - reg.apply_patchfile(os.path.join(setup_dir, "provision.reg")) + # FIXME: Still fails for some reason: + #reg.mount(paths.hklm, registry.HKEY_LOCAL_MACHINE, []) + #reg.apply_patchfile(os.path.join(setup_dir, "provision.reg")) message("Setting up templates into %s" % paths.templates) setup_ldb(setup_dir, "provision_templates.ldif", session_info, credentials, subobj, paths.templates) Modified: branches/4.0-python/source/scripting/python/sidmodule.c =================================================================== --- branches/4.0-python/source/scripting/python/sidmodule.c 2007-11-19 18:20:55 UTC (rev 26040) +++ branches/4.0-python/source/scripting/python/sidmodule.c 2007-11-19 19:28:19 UTC (rev 26041) @@ -29,7 +29,7 @@ if (!PyArg_ParseTuple(args, "")) return NULL; - str = talloc_asprintf(PyMemCtx(), "S-1-5-21-%8u-%8u-%8u", + str = talloc_asprintf(NULL, "S-1-5-21-%8u-%8u-%8u", (unsigned)generate_random(), (unsigned)generate_random(), (unsigned)generate_random()); Modified: branches/4.0-python/source/scripting/python/uuidmodule.c =================================================================== --- branches/4.0-python/source/scripting/python/uuidmodule.c 2007-11-19 18:20:55 UTC (rev 26040) +++ branches/4.0-python/source/scripting/python/uuidmodule.c 2007-11-19 19:28:19 UTC (rev 26041) @@ -18,7 +18,6 @@ */ #include "includes.h" -#include "scripting/python/talloc.h" #include "Python.h" #include "librpc/ndr/libndr.h" @@ -32,7 +31,7 @@ guid = GUID_random(); - str = GUID_string(PyMemCtx(), &guid); + str = GUID_string(NULL, &guid); if (str == NULL) { PyErr_SetString(PyExc_TypeError, "can't convert uuid to string"); return NULL; Modified: branches/4.0-python/source/setup/provision =================================================================== --- branches/4.0-python/source/setup/provision 2007-11-19 18:20:55 UTC (rev 26040) +++ branches/4.0-python/source/setup/provision 2007-11-19 19:28:19 UTC (rev 26041) @@ -94,18 +94,13 @@ opts = parser.parse_args()[0] -# -# print a message if quiet is not set -# def message(text): + """print a message if quiet is not set.""" if opts.quiet: print text hostname = opts.host_name -# -# main program -# if opts.realm is None or opts.domain is None or opts.host_name is None: if opts.realm is None: print >>sys.stderr, "No realm set"
