forked from mirrors/kore
Append full module path if it is a directory.
This commit is contained in:
parent
31b6365da3
commit
c3ab570f56
12
src/python.c
12
src/python.c
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/un.h>
|
||||
|
@ -1369,9 +1370,16 @@ python_kore_proc(PyObject *self, PyObject *args)
|
|||
static PyObject *
|
||||
python_import(const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
PyObject *module;
|
||||
char *dir, *file, *copy, *p;
|
||||
|
||||
if (stat(path, &st) == -1)
|
||||
fatal("python_import: stat(%s): %s", path, errno_s);
|
||||
|
||||
if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
|
||||
fatal("python_import: '%s' is not a file or directory", path);
|
||||
|
||||
copy = kore_strdup(path);
|
||||
|
||||
if ((file = basename(copy)) == NULL)
|
||||
|
@ -1383,6 +1391,10 @@ python_import(const char *path)
|
|||
*p = '\0';
|
||||
|
||||
python_append_path(dir);
|
||||
|
||||
if (S_ISDIR(st.st_mode))
|
||||
python_append_path(path);
|
||||
|
||||
module = PyImport_ImportModule(file);
|
||||
if (module == NULL)
|
||||
PyErr_Print();
|
||||
|
|
Loading…
Reference in New Issue