r26594: Add right paths to the Python sys.path setting so we don't have to set magic...
authorJelmer Vernooij <jelmer@samba.org>
Tue, 25 Dec 2007 22:36:36 +0000 (16:36 -0600)
committerStefan Metzmacher <metze@samba.org>
Wed, 26 Dec 2007 17:57:07 +0000 (11:57 -0600)
(This used to be commit 2d2674ad79330f59210408fd03e859afc01f40f2)

source4/scripting/python/modules.c
source4/scripting/python/smbpython.c

index 6a766f341208ac6084711d93a61988daf67766ea..2a888706602ef4d8ed4b19ab3ec65fc841aeafac 100644 (file)
@@ -43,3 +43,11 @@ void py_load_samba_modules(void)
                PyImport_ExtendInittab(&py_modules[i]);
        }
 }
+
+void py_update_path(const char *bindir)
+{
+       char *newpath;
+       asprintf(&newpath, "%s:%s/python:%s/../scripting/python", Py_GetPath(), bindir, bindir);
+       PySys_SetPath(newpath);
+       free(newpath);
+}
index 19c458e7acbb37be67954918afe71cf38d89ad35..27286236ef0066af4ad4c61c94e8bff085d5a8b5 100644 (file)
 #include <Python.h>
 
 void py_load_samba_modules(void);
+void py_update_path(const char *bindir);
 
 int main(int argc, char **argv) 
 {
        py_load_samba_modules();
+       Py_Initialize();
+       if (strchr(argv[0], '/') != NULL) {
+               char *bindir = strndup(argv[0], strrchr(argv[0], '/')-argv[0]);
+               py_update_path(bindir);
+               free(bindir);
+       }
        return Py_Main(argc,argv);
 }