2005-09-15 09:58:31 -04:00
|
|
|
/* Python scripting engine */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "scripting/python/core.h"
|
2006-01-29 06:28:05 -05:00
|
|
|
#include <Python.h>
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "config/home.h"
|
|
|
|
#include "main/module.h"
|
|
|
|
#include "util/env.h"
|
|
|
|
#include "util/file.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
|
2006-01-28 14:54:11 -05:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
PyObject *pDict, *pModule;
|
|
|
|
|
|
|
|
void
|
|
|
|
cleanup_python(struct module *module)
|
|
|
|
{
|
|
|
|
if (Py_IsInitialized()) {
|
|
|
|
if (pModule) {
|
|
|
|
Py_DECREF(pModule);
|
|
|
|
}
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
PyErr_Print();
|
|
|
|
PyErr_Clear();
|
|
|
|
}
|
|
|
|
Py_Finalize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
init_python(struct module *module)
|
|
|
|
{
|
|
|
|
unsigned char *python_path = straconcat(elinks_home, ":", CONFDIR, NULL);
|
|
|
|
|
|
|
|
if (!python_path) return;
|
|
|
|
env_set("PYTHONPATH", python_path, -1);
|
|
|
|
mem_free(python_path);
|
|
|
|
Py_Initialize();
|
|
|
|
pModule = PyImport_ImportModule("hooks");
|
|
|
|
|
|
|
|
if (pModule) {
|
|
|
|
pDict = PyModule_GetDict(pModule);
|
|
|
|
} else {
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
PyErr_Print();
|
|
|
|
PyErr_Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|