From 32f545cdf031ebe3718791f18e8fb6b6141fd081 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 28 Aug 2009 20:21:54 -0400 Subject: Simplify EPlugin loading at startup. - Require all EPlugin and EPluginHook subtypes be registered before loading plugins. This drastically simplifies the EPlugin/EPluginHook negotiation. - Turn most EPluginHook subtypes into GTypeModules and register their types from an e_module_load() function (does not include shell hooks). - Convert EPluginLib and the Mono and Python bindings to GTypeModules and register their types from an e_module_load() function, and kill EPluginTypeHook. --- plugins/python/ChangeLog | 38 ---- plugins/python/Makefile.am | 30 ---- plugins/python/example/Makefile.am | 29 ---- plugins/python/example/hello_python.py | 5 - .../python/example/org-gnome-hello-python-ui.xml | 16 -- .../example/org-gnome-hello-python.eplug.xml | 20 --- .../python/org-gnome-evolution-python.eplug.xml | 10 -- plugins/python/python-plugin-loader.c | 192 --------------------- plugins/python/python-plugin-loader.h | 47 ----- 9 files changed, 387 deletions(-) delete mode 100644 plugins/python/ChangeLog delete mode 100644 plugins/python/Makefile.am delete mode 100644 plugins/python/example/Makefile.am delete mode 100644 plugins/python/example/hello_python.py delete mode 100644 plugins/python/example/org-gnome-hello-python-ui.xml delete mode 100644 plugins/python/example/org-gnome-hello-python.eplug.xml delete mode 100644 plugins/python/org-gnome-evolution-python.eplug.xml delete mode 100644 plugins/python/python-plugin-loader.c delete mode 100644 plugins/python/python-plugin-loader.h (limited to 'plugins/python') diff --git a/plugins/python/ChangeLog b/plugins/python/ChangeLog deleted file mode 100644 index 38cd85f29f..0000000000 --- a/plugins/python/ChangeLog +++ /dev/null @@ -1,38 +0,0 @@ -2008-09-24 Philip Withnall - - ** Fixes bug #553479 - - * org-gnome-evolution-python.eplug.xml: String capitalisation - improvements. - -2008-09-12 Sankar P - -License Changes - - * python-plugin-loader.c: - * python-plugin-loader.h: - -2008-07-21 Johnny Jacob - - * Makefile.am (example_sources): More typo fixes. :( - -2008-07-21 Johnny Jacob - - * Makefile.am (example_SOURCES): Add example sources - EXTRA_DIST. - -2008-06-12 Johnny Jacob - - * example/org-gnome-hello-python-ui.xml: Added. - - * example/org-gnome-hello-python.eplug.xml: Added. - - * example/Makefile.am : Added. - - * example/hello_python.py: Added. - -2008-06-09 Johnny Jacob - - * python-plugin-loader.c: Python plugin loader. - Initial Commit. - diff --git a/plugins/python/Makefile.am b/plugins/python/Makefile.am deleted file mode 100644 index 6f62036a1d..0000000000 --- a/plugins/python/Makefile.am +++ /dev/null @@ -1,30 +0,0 @@ -AM_CPPFLAGS = \ - -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 $(NO_UNDEFINED) -liborg_gnome_evolution_python_la_LIBADD = \ - -lpthread -ldl -lutil -lm \ - $(PY_LIBS) \ - $(E_UTIL_LIBS) - -example_sources = \ - example/hello_python.py \ - example/org-gnome-hello-python-ui.xml \ - example/org-gnome-hello-python.eplug.xml \ - example/Makefile.am - -EXTRA_DIST = org-gnome-evolution-python.eplug.xml \ - $(example_sources) - -BUILT_SOURCES = $(plugin_DATA) -CLEANFILES = $(BUILT_SOURCES) - --include $(top_srcdir)/git.mk diff --git a/plugins/python/example/Makefile.am b/plugins/python/example/Makefile.am deleted file mode 100644 index cc14dc94d9..0000000000 --- a/plugins/python/example/Makefile.am +++ /dev/null @@ -1,29 +0,0 @@ -AM_CPPFLAGS = \ - -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ - -DEVOLUTION_IMAGESDIR=\""$(imagesdir)"\" - -@EVO_PLUGIN_RULE@ - -plugin_DATA = \ - hello_python.py \ - org-gnome-hello-python-ui.xml \ - org-gnome-hello-python.eplug - -liborg_gnome_py_plug_test_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED) - -errordir = $(privdatadir)/errors - -BUILDME = org-gnome-hello-python.eplug \ -$(error_i18n) - -BUILT_SOURCES = \ - $(BUILDME) - -EXTRA_DIST = \ - hello_python.py \ - org-gnome-hello-python-ui.xml \ - org-gnome-hello-python.eplug.xml - -CLEANFILES = $(BUILT_SOURCES) - --include $(top_srcdir)/git.mk diff --git a/plugins/python/example/hello_python.py b/plugins/python/example/hello_python.py deleted file mode 100644 index 16dc2a12f8..0000000000 --- a/plugins/python/example/hello_python.py +++ /dev/null @@ -1,5 +0,0 @@ -'''hello_python.py - Python source designed to ''' -'''demonstrate the use of python Eplugins''' - -def say_hello(): - print 'Hello ! From python' diff --git a/plugins/python/example/org-gnome-hello-python-ui.xml b/plugins/python/example/org-gnome-hello-python-ui.xml deleted file mode 100644 index 074960e84d..0000000000 --- a/plugins/python/example/org-gnome-hello-python-ui.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - diff --git a/plugins/python/example/org-gnome-hello-python.eplug.xml b/plugins/python/example/org-gnome-hello-python.eplug.xml deleted file mode 100644 index 8f77d5ba01..0000000000 --- a/plugins/python/example/org-gnome-hello-python.eplug.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - <_description> - Test Plugin for Python EPlugin loader. - - - - - - - - - - - - diff --git a/plugins/python/org-gnome-evolution-python.eplug.xml b/plugins/python/org-gnome-evolution-python.eplug.xml deleted file mode 100644 index 5f215f65e5..0000000000 --- a/plugins/python/org-gnome-evolution-python.eplug.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - <_description>A plugin which loads other plugins written using Python. - - - - diff --git a/plugins/python/python-plugin-loader.c b/plugins/python/python-plugin-loader.c deleted file mode 100644 index 0a03809e97..0000000000 --- a/plugins/python/python-plugin-loader.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Johnny Jacob - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include -#include -#include - -#include "python-plugin-loader.h" - -#define d(x) - -static gpointer epp_parent_class; - -typedef struct _EPluginPythonPrivate { - PyObject *pModule; - PyObject *pClass; - PyObject *pFunc; - PyObject *pDict; - GHashTable *methods; -} EPluginPythonPrivate; - -#define epp ((EPluginPython *)ep) - -gpointer load_plugin_type_register_function (gpointer a, gpointer b); - -static gchar * -get_xml_prop(xmlNodePtr node, const gchar *id) -{ - gchar *p = xmlGetProp(node, id); - gchar *out = NULL; - - if (p) { - out = g_strdup(p); - xmlFree(p); - } - - return out; -} - -static gpointer -epp_invoke(EPlugin *ep, const gchar *name, gpointer 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 gint -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); -} - -gpointer -load_plugin_type_register_function (gpointer a, gpointer 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 deleted file mode 100644 index 66bd8d5ba2..0000000000 --- a/plugins/python/python-plugin-loader.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Johnny Jacob - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#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; - - gchar *location; /* location */ - gchar *pClass; /* handler class */ - gchar *module_name; -}; - -struct _EPluginPythonClass { - EPluginClass plugin_class; -}; - -gpointer org_gnome_evolution_python_get_type(gpointer a, gpointer b); - -#endif /* ! _ORG_GNOME_EVOLUTION_PYTHON_H */ -- cgit v1.2.3