evolution r35626 - in trunk: . plugins/python



Author: jjohnny
Date: Wed Jun 11 16:25:48 2008
New Revision: 35626
URL: http://svn.gnome.org/viewvc/evolution?rev=35626&view=rev

Log:
EPlugin : Initial commit for python support for eplugins.


Added:
   trunk/plugins/python/
   trunk/plugins/python/ChangeLog
   trunk/plugins/python/Makefile.am
   trunk/plugins/python/org-gnome-evolution-python.eplug.xml
   trunk/plugins/python/python-plugin-loader.c
   trunk/plugins/python/python-plugin-loader.h
Modified:
   trunk/ChangeLog
   trunk/configure.in

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Wed Jun 11 16:25:48 2008
@@ -899,6 +899,46 @@
 	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 @@
 
 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 @@
 	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/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

Added: trunk/plugins/python/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/plugins/python/Makefile.am	Wed Jun 11 16:25:48 2008
@@ -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)

Added: trunk/plugins/python/org-gnome-evolution-python.eplug.xml
==============================================================================
--- (empty file)
+++ trunk/plugins/python/org-gnome-evolution-python.eplug.xml	Wed Jun 11 16:25:48 2008
@@ -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>

Added: trunk/plugins/python/python-plugin-loader.c
==============================================================================
--- (empty file)
+++ trunk/plugins/python/python-plugin-loader.c	Wed Jun 11 16:25:48 2008
@@ -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);
+}

Added: trunk/plugins/python/python-plugin-loader.h
==============================================================================
--- (empty file)
+++ trunk/plugins/python/python-plugin-loader.h	Wed Jun 11 16:25:48 2008
@@ -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 */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]