Author: jelmer Date: 2007-12-25 16:36:36 +0000 (Tue, 25 Dec 2007) New Revision: 26594
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=26594 Log: 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. Modified: branches/SAMBA_4_0/ branches/SAMBA_4_0/source/scripting/python/modules.c branches/SAMBA_4_0/source/scripting/python/smbpython.c Changeset: Property changes on: branches/SAMBA_4_0 ___________________________________________________________________ Name: bzr:revision-info ...skipped... Name: bzr:revision-id:v3-trunk0 ...skipped... Modified: branches/SAMBA_4_0/source/scripting/python/modules.c =================================================================== --- branches/SAMBA_4_0/source/scripting/python/modules.c 2007-12-25 16:36:31 UTC (rev 26593) +++ branches/SAMBA_4_0/source/scripting/python/modules.c 2007-12-25 16:36:36 UTC (rev 26594) @@ -43,3 +43,11 @@ 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); +} Modified: branches/SAMBA_4_0/source/scripting/python/smbpython.c =================================================================== --- branches/SAMBA_4_0/source/scripting/python/smbpython.c 2007-12-25 16:36:31 UTC (rev 26593) +++ branches/SAMBA_4_0/source/scripting/python/smbpython.c 2007-12-25 16:36:36 UTC (rev 26594) @@ -21,9 +21,16 @@ #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); }
