From fe2b04b4bba6585ee5377d44b8e2627d32d404c4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Apr 2009 01:20:20 +0200 Subject: python: Move helper functions for using param into a separate file rather than linking against the python module. --- source4/param/pyparam_util.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 source4/param/pyparam_util.c (limited to 'source4/param/pyparam_util.c') diff --git a/source4/param/pyparam_util.c b/source4/param/pyparam_util.c new file mode 100644 index 0000000000..0dc7c7fd13 --- /dev/null +++ b/source4/param/pyparam_util.c @@ -0,0 +1,54 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2007-2008 + + 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 3 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, see . +*/ + +#include +#include + +#include "includes.h" +#include "param/param.h" +#include "param/loadparm.h" +#include +#include "pytalloc.h" + +#define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_type(obj, struct loadparm_context) + +_PUBLIC_ struct loadparm_context *lp_from_py_object(PyObject *py_obj) +{ + struct loadparm_context *lp_ctx; + + if (PyString_Check(py_obj)) { + lp_ctx = loadparm_init(NULL); + if (!lp_load(lp_ctx, PyString_AsString(py_obj))) { + talloc_free(lp_ctx); + PyErr_Format(PyExc_RuntimeError, "Unable to load %s", + PyString_AsString(py_obj)); + return NULL; + } + return lp_ctx; + } + + if (py_obj == Py_None) { + lp_ctx = loadparm_init(NULL); + /* We're not checking that loading the file succeeded *on purpose */ + lp_load_default(lp_ctx); + return lp_ctx; + } + + return PyLoadparmContext_AsLoadparmContext(py_obj); +} -- cgit