summaryrefslogtreecommitdiff
path: root/source4/scripting/python/modules.c
diff options
context:
space:
mode:
authorNadezhda Ivanova <nadezhda.ivanova@postpath.com>2010-01-04 11:24:10 +0200
committerNadezhda Ivanova <nadezhda.ivanova@postpath.com>2010-01-04 11:24:10 +0200
commitfb5383c69ee52fb5e6d066a43451dc8c806cc795 (patch)
tree45b72e03f68ab6d212755c524f8e8a60a3b4373a /source4/scripting/python/modules.c
parent60d8ab3b7b0bd2c9b633f0380d1fdf5bcf5e2621 (diff)
parenta06e5cdb99ddf7abf16486d3837105ec4e0da9ee (diff)
downloadsamba-fb5383c69ee52fb5e6d066a43451dc8c806cc795.tar.gz
samba-fb5383c69ee52fb5e6d066a43451dc8c806cc795.tar.bz2
samba-fb5383c69ee52fb5e6d066a43451dc8c806cc795.zip
Merge branch 'master' of git://git.samba.org/samba
Diffstat (limited to 'source4/scripting/python/modules.c')
-rw-r--r--source4/scripting/python/modules.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/source4/scripting/python/modules.c b/source4/scripting/python/modules.c
index 5365c5007d..198b3ccf12 100644
--- a/source4/scripting/python/modules.c
+++ b/source4/scripting/python/modules.c
@@ -61,10 +61,47 @@ void py_load_samba_modules(void)
}
}
-void py_update_path(const char *bindir)
+static bool PySys_PathPrepend(PyObject *list, const char *path)
+{
+ PyObject *py_path = PyString_FromString(path);
+ if (py_path == NULL)
+ return false;
+
+ return (PyList_Insert(list, 0, py_path) == 0);
+}
+
+bool py_update_path(const char *bindir)
{
char *newpath;
- asprintf(&newpath, "%s/python:%s/../scripting/python:%s", bindir, bindir, Py_GetPath());
- PySys_SetPath(newpath);
+ PyObject *mod_sys, *py_path;
+
+ mod_sys = PyImport_ImportModule("sys");
+ if (mod_sys == NULL) {
+ return false;
+ }
+
+ py_path = PyObject_GetAttrString(mod_sys, "path");
+ if (py_path == NULL) {
+ return false;
+ }
+
+ if (!PyList_Check(py_path)) {
+ return false;
+ }
+
+ asprintf(&newpath, "%s/../scripting/python", bindir);
+ if (!PySys_PathPrepend(py_path, newpath)) {
+ free(newpath);
+ return false;
+ }
free(newpath);
+
+ asprintf(&newpath, "%s/python", bindir);
+ if (!PySys_PathPrepend(py_path, newpath)) {
+ free(newpath);
+ return false;
+ }
+ free(newpath);
+
+ return true;
}