about summary refs log tree commit diff stats
path: root/src/plugins/python_plugins.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/python_plugins.c')
-rw-r--r--src/plugins/python_plugins.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c
index a73cc15b..7861f484 100644
--- a/src/plugins/python_plugins.c
+++ b/src/plugins/python_plugins.c
@@ -62,27 +62,17 @@ python_env_init(void)
     Py_Initialize();
     PyEval_InitThreads();
     python_api_init();
-    GString *path = g_string_new(Py_GetPath());
 
-    g_string_append(path, ":");
+    GString *path = g_string_new("import sys\n");
+    g_string_append(path, "sys.path.append(\"");
     gchar *plugins_dir = plugins_get_dir();
     g_string_append(path, plugins_dir);
-    g_string_append(path, "/");
     g_free(plugins_dir);
+    g_string_append(path, "/\")\n");
 
-    PySys_SetPath(path->str);
-    g_string_free(path, TRUE);
-
-    // add site packages paths
-    PyRun_SimpleString(
-        "import site\n"
-        "import sys\n"
-        "from distutils.sysconfig import get_python_lib\n"
-        "sys.path.append(get_python_lib())\n"
-        "for dir in site.getsitepackages():\n"
-        "   sys.path.append(dir)\n"
-    );
+    PyRun_SimpleString(path->str);
 
+    g_string_free(path, TRUE);
     allow_python_threads();
 }
 
@@ -138,10 +128,11 @@ python_plugin_create(const char *const filename)
 }
 
 void
-python_init_hook(ProfPlugin *plugin, const char *const version, const char *const status)
+python_init_hook(ProfPlugin *plugin, const char *const version, const char *const status, const char *const account_name,
+    const char *const fulljid)
 {
     disable_python_threads();
-    PyObject *p_args = Py_BuildValue("ss", version, status);
+    PyObject *p_args = Py_BuildValue("ssss", version, status, account_name, fulljid);
     PyObject *p_function;
 
     PyObject *p_module = plugin->module;
@@ -655,7 +646,7 @@ python_on_message_stanza_receive_hook(ProfPlugin *plugin, const char *const text
             PyObject *result = PyObject_CallObject(p_function, p_args);
             python_check_error();
             Py_XDECREF(p_function);
-            if (PyBool_Check(result)) {
+            if (PyObject_IsTrue(result)) {
                 allow_python_threads();
                 return TRUE;
             } else {
@@ -720,7 +711,7 @@ python_on_presence_stanza_receive_hook(ProfPlugin *plugin, const char *const tex
             PyObject *result = PyObject_CallObject(p_function, p_args);
             python_check_error();
             Py_XDECREF(p_function);
-            if (PyBool_Check(result)) {
+            if (PyObject_IsTrue(result)) {
                 allow_python_threads();
                 return TRUE;
             } else {
@@ -785,7 +776,7 @@ python_on_iq_stanza_receive_hook(ProfPlugin *plugin, const char *const text)
             PyObject *result = PyObject_CallObject(p_function, p_args);
             python_check_error();
             Py_XDECREF(p_function);
-            if (PyBool_Check(result)) {
+            if (PyObject_IsTrue(result)) {
                 allow_python_threads();
                 return TRUE;
             } else {