s4-python Don't force "bin" into the python sys.path
authorAndrew Bartlett <abartlet@samba.org>
Sat, 5 Feb 2011 07:00:45 +0000 (18:00 +1100)
committerAndrew Tridgell <tridge@samba.org>
Mon, 7 Feb 2011 02:22:02 +0000 (13:22 +1100)
This patch uses the fact that dyn_PYTHONDIR and dyn_PYTHONARCHDIR is
now set properly at all times, incluidng for installed and
build-directory binaries.  So we don't need to make assumptions about
bin being magic any more.

Andrew Bartlett

source4/param/provision.c
source4/samba_tool/samba_tool.c
source4/scripting/python/modules.c
source4/scripting/python/modules.h
source4/web_server/wsgi.c

index e4236a59c5a67bd2a203e555a7e6312ce60499cb..7b6e6e74b3511329122c5d908800d949a3e57288 100644 (file)
@@ -84,7 +84,7 @@ NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
        DEBUG(0,("Provision for Become-DC test using python\n"));
 
        Py_Initialize();
-       py_update_path("bin"); /* FIXME: Can't assume this is always the case */
+       py_update_path(); /* Put the samba path at the start of sys.path */
 
        provision_mod = provision_module();
 
@@ -240,7 +240,7 @@ NTSTATUS provision_store_self_join(TALLOC_CTX *mem_ctx, struct loadparm_context
        }
 
        Py_Initialize();
-       py_update_path("bin"); /* FIXME: Can't assume this is always the case */
+       py_update_path(); /* Put the samba path at the start of sys.path */
        provision_mod = provision_module();
 
        if (provision_mod == NULL) {
@@ -336,7 +336,7 @@ struct ldb_context *provision_get_schema(TALLOC_CTX *mem_ctx, struct loadparm_co
        PyObject *schema_mod, *schema_dict, *schema_fn, *py_result, *parameters;
        
        Py_Initialize();
-       py_update_path("bin"); /* FIXME: Can't assume this is always the case */
+       py_update_path(); /* Put the samba path at the start of sys.path */
 
        schema_mod = schema_module();
 
index da08a716ce111a1fde1c24f6e5106b712433a4b7..411eb6d98d17bf1d51467401c50db478b3650ca8 100644 (file)
@@ -308,7 +308,7 @@ static int binary_net(int argc, const char **argv)
        }
        Py_Initialize();
        PySys_SetArgv(argc, discard_const_p(char *, argv));
-       py_update_path("bin"); /* FIXME: Can't assume this is always the case */
+       py_update_path(); /* Put the Samba path at the start of sys.path */
 
        py_cmds = py_commands();
        if (py_cmds == NULL) {
index 960239e8636ecc23a03ae4d05ef3b51db238660a..f2a45a98932271fce1f7b88946c3bc433e2e6153 100644 (file)
@@ -31,7 +31,7 @@ static bool PySys_PathPrepend(PyObject *list, const char *path)
        return (PyList_Insert(list, 0, py_path) == 0);
 }
 
-bool py_update_path(const char *bindir)
+bool py_update_path()
 {
        char *newpath;
        PyObject *mod_sys, *py_path;
@@ -58,23 +58,5 @@ bool py_update_path(const char *bindir)
                return false;
        }
 
-       if (asprintf(&newpath, "%s/../scripting/python", bindir) < 0) {
-               return false;
-       }
-       if (!PySys_PathPrepend(py_path, newpath)) {
-               free(newpath);
-               return false;
-       }
-       free(newpath);
-
-       if (asprintf(&newpath, "%s/python", bindir) < 0) {
-               return false;
-       }
-       if (!PySys_PathPrepend(py_path, newpath)) {
-               free(newpath);
-               return false;
-       }
-       free(newpath);
-
        return true;
 }
index 7c15fecabeff215b45159f1ab61b6c909408ce49..4e43e6de1dd809441e819b9f3cfd00333e178f11 100644 (file)
@@ -20,6 +20,6 @@
 #ifndef __SAMBA_PYTHON_MODULES_H__
 #define __SAMBA_PYTHON_MODULES_H__
 
-bool py_update_path(const char *bindir);
+bool py_update_path();
 
 #endif /* __SAMBA_PYTHON_MODULES_H__ */ 
index 2f47af2d257aa9d33b05eec211b980cd9791df40..37ded294801d5caee4b1dbd3a2c2af623c0e6964 100644 (file)
@@ -385,7 +385,8 @@ bool wsgi_initialize(struct web_server_data *wdata)
 
        Py_Initialize();
 
-       py_update_path("bin"); /* FIXME: Can't assume this is always the case */
+       py_update_path(); /* Ensure that we have the Samba paths at
+                          * the start of the sys.path() */
 
        if (PyType_Ready(&web_request_Type) < 0)
                return false;