diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | configure.in | 53 | ||||
-rw-r--r-- | plugins/python/ChangeLog | 5 | ||||
-rw-r--r-- | plugins/python/Makefile.am | 21 | ||||
-rw-r--r-- | plugins/python/org-gnome-evolution-python.eplug.xml | 10 | ||||
-rw-r--r-- | plugins/python/python-plugin-loader.c | 191 | ||||
-rw-r--r-- | plugins/python/python-plugin-loader.h | 47 |
7 files changed, 330 insertions, 2 deletions
@@ -1,3 +1,8 @@ +2008-06-11 Johnny Jacob <jjohnny@novell.com> + + ** Partially fixes #506393 + * configure.in : Adding python plugin loader (--enable-python). + 2008-06-06 Matthew Barnes <mbarnes@redhat.com> ** Allow evolution to build with G_DISABLE_SINGLE_INCLUDES and diff --git a/configure.in b/configure.in index 2e2ac2c43b..6c803a28b9 100644 --- a/configure.in +++ b/configure.in @@ -899,6 +899,46 @@ if test "x${enable_mono}" = "xyes"; then MONO_PLUGIN="mono" fi +dnl Python hooks +dnl This should just define python CFLAGS etc here, it is used later to +dnl turn on the python plugin or not. +dnl (Thanks to Pidgin) + +AC_ARG_ENABLE([python], + AC_HELP_STRING([--enable-python], + [Add python embedded hooks.]), + [enable_python=$enableval],[enable_python=no]) + +if test "x${enable_python}" = "xyes"; then + AC_PATH_PROG(pythonpath, python) + if test "_$pythonpath" != _ ; then + AC_MSG_CHECKING(for python compile flags) + PY_PREFIX=`$pythonpath -c 'import sys ; print sys.prefix'` + PY_EXEC_PREFIX=`$pythonpath -c 'import sys ; print sys.exec_prefix'` + changequote(<<, >>)dnl + PY_VERSION=`$pythonpath -c 'import sys ; print sys.version[0:3]'` + PY_MAJOR=`$pythonpath -c 'import sys ; print sys.version[0:2]'` + changequote([, ])dnl + + if test -f $PY_PREFIX/include/python$PY_VERSION/Python.h -a "$PY_MAJOR" = "2."; then + PY_LIBS="-lpython$PY_VERSION -L$PY_EXEC_PREFIX/lib/python$PY_VERSION/config" + PY_INCLUDES="-I$PY_PREFIX/include/python$PY_VERSION" + AC_MSG_RESULT(ok) + python_package="python-devel" + PYTHON_PLUGIN="python" + else + AC_MSG_ERROR([Can't find Python.h]) + PY_LIBS="" + PY_INCLUDES="" + python_package="" + PYTHON_PLUGIN="" + fi + fi + AC_SUBST(PY_LIBS) + AC_SUBST(PY_INCLUDES) +fi + + dnl ******************************************************************************** dnl security extension support (SSL and S/MIME) dnl @@ -1691,15 +1731,17 @@ AC_ARG_ENABLE([plugins], dnl Add any new plugins here plugins_base_always="calendar-file calendar-http calendar-weather itip-formatter plugin-manager default-source addressbook-file startup-wizard mark-all-read groupwise-features groupwise-account-setup hula-account-setup mail-account-disable publish-calendar caldav imap-features google-account-setup" -plugins_base="$plugins_base_always $SA_JUNK_PLUGIN $BF_JUNK_PLUGIN $EXCHANGE_PLUGIN $MONO_PLUGIN" + +plugins_base="$plugins_base_always $SA_JUNK_PLUGIN $BF_JUNK_PLUGIN $EXCHANGE_PLUGIN $MONO_PLUGIN " all_plugins_base="$plugins_base_always sa-junk-plugin bogo-junk-plugin exchange-operations mono" plugins_standard_always="bbdb subject-thread save-calendar select-one-source copy-tool mail-to-task mark-calendar-offline audio-inline mailing-list-actions default-mailer import-ics-attachments prefer-plain mail-notification attachment-reminder face backup-restore email-custom-header" + plugins_standard="$plugins_standard_always" all_plugins_standard="$plugins_standard" plugins_experimental_always="folder-unsubscribe mail-to-meeting save-attachments external-editor" -plugins_experimental="$plugins_experimental_always $IPOD_SYNC $TNEF_ATTACHMENTS" +plugins_experimental="$plugins_experimental_always $IPOD_SYNC $TNEF_ATTACHMENTS $PYTHON_PLUGIN" all_plugins_experimental="$plugins_experimental_always ipod-sync tnef-attachments" case x"$enable_plugins" in @@ -1742,6 +1784,12 @@ if test "x${enable_mono}" = "xyes"; then msg_plugins="$msg_plugins (and mono)" fi + +if test "x${enable_python}" = "xyes"; then + plugins_enabled="$plugins_enabled python" + msg_plugins="$msg_plugins (and python)" +fi + AC_SUBST(plugins_enabled) AC_SUBST(all_plugins_base) AC_SUBST(all_plugins_standard) @@ -1974,6 +2022,7 @@ plugins/select-one-source/Makefile plugins/mark-calendar-offline/Makefile plugins/prefer-plain/Makefile plugins/profiler/Makefile +plugins/python/Makefile plugins/copy-tool/Makefile plugins/folder-unsubscribe/Makefile plugins/mailing-list-actions/Makefile diff --git a/plugins/python/ChangeLog b/plugins/python/ChangeLog new file mode 100644 index 0000000000..393e1034b5 --- /dev/null +++ b/plugins/python/ChangeLog @@ -0,0 +1,5 @@ +2008-06-09 Johnny Jacob <jjohnny@novell.com> + + * python-plugin-loader.c: Python plugin loader. + Initial Commit. + diff --git a/plugins/python/Makefile.am b/plugins/python/Makefile.am new file mode 100644 index 0000000000..854c7915f6 --- /dev/null +++ b/plugins/python/Makefile.am @@ -0,0 +1,21 @@ +INCLUDES = \ + -I$(top_srcdir) \ + $(E_UTIL_CFLAGS) \ + $(PY_INCLUDES) + +@EVO_PLUGIN_RULE@ + +plugin_DATA = org-gnome-evolution-python.eplug +plugin_LTLIBRARIES = liborg-gnome-evolution-python.la + +liborg_gnome_evolution_python_la_SOURCES = python-plugin-loader.c python-plugin-loader.h +liborg_gnome_evolution_python_la_LDFLAGS = -module -avoid-version +liborg_gnome_evolution_python_la_LIBADD = \ + -lpthread -ldl -lutil -lm \ + $(PY_LIBS) \ + $(E_UTIL_LIBS) + +EXTRA_DIST = org-gnome-evolution-python.eplug.xml + +BUILT_SOURCES = $(plugin_DATA) +CLEANFILES = $(BUILT_SOURCES) diff --git a/plugins/python/org-gnome-evolution-python.eplug.xml b/plugins/python/org-gnome-evolution-python.eplug.xml new file mode 100644 index 0000000000..c8cfd20f27 --- /dev/null +++ b/plugins/python/org-gnome-evolution-python.eplug.xml @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<e-plugin-list> + <e-plugin type="shlib" id="org.gnome.evolution.plugin.python" + location="@PLUGINDIR@/liborg-gnome-evolution-python@SOEXT@" _name="Python Loader" load_level="1"> + + <_description>A plugin which loads other plugins written using python.</_description> + + <author name="Johnny Jacob" email="jjohnny@novell.com"/> + </e-plugin> +</e-plugin-list> diff --git a/plugins/python/python-plugin-loader.c b/plugins/python/python-plugin-loader.c new file mode 100644 index 0000000000..2d09aba72f --- /dev/null +++ b/plugins/python/python-plugin-loader.c @@ -0,0 +1,191 @@ + /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Author: Johnny Jacob <jjohnny@novell.com> + * + * Copyright 2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include <sys/types.h> +#include <string.h> +#include <Python.h> + +#include "python-plugin-loader.h" + +#define d(x) + +static void *epp_parent_class; + +typedef struct _EPluginPythonPrivate { + PyObject *pModule; + PyObject *pClass; + PyObject *pFunc; + PyObject *pDict; + GHashTable *methods; +} EPluginPythonPrivate; + +#define epp ((EPluginPython *)ep) + +void * load_plugin_type_register_function (void *a, void *b); + +static char * +get_xml_prop(xmlNodePtr node, const char *id) +{ + char *p = xmlGetProp(node, id); + char *out = NULL; + + if (p) { + out = g_strdup(p); + xmlFree(p); + } + + return out; +} + +static void * +epp_invoke(EPlugin *ep, const char *name, void *data) +{ + EPluginPythonPrivate *p = epp->priv; + PyObject *pModuleName, *pFunc; + PyObject *pInstance, *pValue = NULL; + + /* we need to do this every time since we may be called from any thread for some uses */ + Py_Initialize(); + + if (p->pModule == NULL) { + pModuleName = PyString_FromString(epp->module_name); + + PyRun_SimpleString(g_strdup_printf ("import sys ; sys.path.insert(0, '%s')", epp->location)); + + p->pModule = PyImport_Import(pModuleName); + + Py_DECREF(pModuleName); //Free + + if (p->pModule == NULL) { + PyErr_Print(); + g_warning("can't load python module '%s'", epp->location); + return NULL; + } + + p->pDict = PyModule_GetDict(p->pModule); + + if (epp->pClass) { + p->pClass = PyDict_GetItemString(p->pDict, epp->pClass); + } + } + + if (p->pClass) { + + if (PyCallable_Check(p->pClass)) + pInstance = PyObject_CallObject(p->pClass, NULL); + + pValue = PyObject_CallMethod(pInstance, name, NULL); + + } else { + + pFunc = PyDict_GetItemString(p->pDict, name); + + if (pFunc && PyCallable_Check(pFunc)) + pValue = PyObject_CallObject(pFunc, NULL); + else + PyErr_Print(); + } + + if (pValue) { + d(printf("%s(%d):%s: Result of call: %ld \n", __FILE__, __LINE__, __PRETTY_FUNCTION__, PyInt_AsLong(pValue))); + Py_DECREF(pValue); + /* Fixme */ + return NULL; + } else + return NULL; +} + +static int +epp_construct(EPlugin *ep, xmlNodePtr root) +{ + if (((EPluginClass *)epp_parent_class)->construct(ep, root) == -1) + return -1; + + epp->location = get_xml_prop(root, "location"); + epp->module_name = get_xml_prop (root, "module_name"); + epp->pClass = get_xml_prop(root, "pClass"); + + if (epp->location == NULL) + return -1; + + return 0; +} + +static void +epp_finalise(GObject *o) +{ + EPlugin *ep = (EPlugin *)o; + EPluginPythonPrivate *p = epp->priv; + + g_free(epp->location); + g_free(epp->module_name); + g_free(epp->pClass); + + g_hash_table_destroy(p->methods); + + g_free(epp->priv); + + ((GObjectClass *)epp_parent_class)->finalize(o); +} + +static void +epp_class_init(EPluginClass *klass) +{ + ((GObjectClass *)klass)->finalize = epp_finalise; + klass->construct = epp_construct; + klass->invoke = epp_invoke; + klass->type = "python"; +} + +static void +epp_init(GObject *o) +{ + EPlugin *ep = (EPlugin *)o; + + epp->priv = g_malloc0(sizeof(*epp->priv)); + epp->priv->methods = g_hash_table_new_full( + g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) NULL); +} + +void * +load_plugin_type_register_function (void *a, void *b) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo info = { + sizeof(EPluginPythonClass), NULL, NULL, (GClassInitFunc) epp_class_init, NULL, NULL, + sizeof(EPluginPython), 0, (GInstanceInitFunc) epp_init, + }; + + epp_parent_class = g_type_class_ref(e_plugin_get_type()); + type = g_type_register_static(e_plugin_get_type(), "EPluginPython", &info, 0); + e_plugin_register_type (type); + + d(printf("\nType EPluginPython registered from the python-plugin-loader\n")); + + Py_Initialize(); //TODO : Does this mean i can cache the instance of pyobjects ? + } + + return GUINT_TO_POINTER(type); +} diff --git a/plugins/python/python-plugin-loader.h b/plugins/python/python-plugin-loader.h new file mode 100644 index 0000000000..a7c9ff1f07 --- /dev/null +++ b/plugins/python/python-plugin-loader.h @@ -0,0 +1,47 @@ + /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Author: Johnny Jacob <jjohnny@novell.com> + * + * Copyright 2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef _ORG_GNOME_EVOLUTION_PYTHON_H +#define _ORG_GNOME_EVOLUTION_PYTHON_H + +#include "e-util/e-plugin.h" + +typedef struct _EPluginPython EPluginPython; +typedef struct _EPluginPythonClass EPluginPythonClass; + +struct _EPluginPython { + EPlugin plugin; + + struct _EPluginPythonPrivate *priv; + + char *location; /* location */ + char *pClass; /* handler class */ + char *module_name; +}; + +struct _EPluginPythonClass { + EPluginClass plugin_class; +}; + +void *org_gnome_evolution_python_get_type(void *a, void *b); + + +#endif /* ! _ORG_GNOME_EVOLUTION_PYTHON_H */ |