| Line | |
|---|
| 1 | #include "Python.h"
|
|---|
| 2 | #include "osdefs.h"
|
|---|
| 3 |
|
|---|
| 4 | static char *prefix, *exec_prefix, *progpath, *module_search_path=NULL;
|
|---|
| 5 |
|
|---|
| 6 | static void
|
|---|
| 7 | calculate_path()
|
|---|
| 8 | {
|
|---|
| 9 | char *pypath = getenv("Python$Path");
|
|---|
| 10 | if (pypath) {
|
|---|
| 11 | int pathlen = strlen(pypath);
|
|---|
| 12 | module_search_path = malloc(pathlen + 1);
|
|---|
| 13 | if (module_search_path)
|
|---|
| 14 | strncpy(module_search_path, pypath, pathlen + 1);
|
|---|
| 15 | else {
|
|---|
| 16 | fprintf(stderr,
|
|---|
| 17 | "Not enough memory for dynamic PYTHONPATH.\n"
|
|---|
| 18 | "Using default static PYTHONPATH.\n");
|
|---|
| 19 | }
|
|---|
| 20 | }
|
|---|
| 21 | if (!module_search_path)
|
|---|
| 22 | module_search_path = "<Python$Dir>.Lib";
|
|---|
| 23 | prefix = "<Python$Dir>";
|
|---|
| 24 | exec_prefix = prefix;
|
|---|
| 25 | progpath = Py_GetProgramName();
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | /* External interface */
|
|---|
| 29 |
|
|---|
| 30 | char *
|
|---|
| 31 | Py_GetPath()
|
|---|
| 32 | {
|
|---|
| 33 | if (!module_search_path)
|
|---|
| 34 | calculate_path();
|
|---|
| 35 | return module_search_path;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | char *
|
|---|
| 39 | Py_GetPrefix()
|
|---|
| 40 | {
|
|---|
| 41 | if (!module_search_path)
|
|---|
| 42 | calculate_path();
|
|---|
| 43 | return prefix;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | char *
|
|---|
| 47 | Py_GetExecPrefix()
|
|---|
| 48 | {
|
|---|
| 49 | if (!module_search_path)
|
|---|
| 50 | calculate_path();
|
|---|
| 51 | return exec_prefix;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | char *
|
|---|
| 55 | Py_GetProgramFullPath()
|
|---|
| 56 | {
|
|---|
| 57 | if (!module_search_path)
|
|---|
| 58 | calculate_path();
|
|---|
| 59 | return progpath;
|
|---|
| 60 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.