From e8bca8dd71c9bb64b84f6a74632a46a661be0d97 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 25 Dec 2007 16:36:36 -0600 Subject: r26594: Add right paths to the Python sys.path setting so we don't have to set magic environment variables when running from the build directory. (This used to be commit 2d2674ad79330f59210408fd03e859afc01f40f2) --- source4/scripting/python/modules.c | 8 ++++++++ source4/scripting/python/smbpython.c | 7 +++++++ 2 files changed, 15 insertions(+) (limited to 'source4/scripting') diff --git a/source4/scripting/python/modules.c b/source4/scripting/python/modules.c index 6a766f3412..2a88870660 100644 --- a/source4/scripting/python/modules.c +++ b/source4/scripting/python/modules.c @@ -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); +} diff --git a/source4/scripting/python/smbpython.c b/source4/scripting/python/smbpython.c index 19c458e7ac..27286236ef 100644 --- a/source4/scripting/python/smbpython.c +++ b/source4/scripting/python/smbpython.c @@ -21,9 +21,16 @@ #include 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); } -- cgit