Index: configure.ac
===================================================================
RCS file: /cvs/gstreamer/gst-python/configure.ac,v
retrieving revision 1.61.2.5
diff -u -3 -p -r1.61.2.5 configure.ac
--- configure.ac	2 May 2005 23:32:31 -0000	1.61.2.5
+++ configure.ac	16 May 2005 14:06:30 -0000
@@ -51,6 +51,102 @@ else
 fi
 AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers)])
 
+dnl **************************************************
+dnl * Check for Python
+dnl **************************************************
+try_python=true
+try_pygtk=false
+python_msg=no
+AC_ARG_WITH(python,
+	[--{with,without}-python   Compile the Python plugin loader],
+	if test "x$withval" = xno; then
+		python_msg="Disabled by request"
+		try_python=false
+	else
+		python_prog="$withval"
+	fi
+)
+
+if $try_python; then
+	if test "x$python_prog" = xyes -o "x$python_prog" = x ; then
+	    python_prog=python
+	fi
+
+	python_val=
+	python_msg="unable to find python"
+	AC_CHECK_PROG(python_val, "$python_prog", true, false)
+	if $python_val; then
+		  AC_MSG_CHECKING(for python >= 2.3)
+		  PY_PREFIX=`$python_prog -c 'import sys ; print sys.prefix'`
+		  PY_EXEC_PREFIX=`$python_prog -c 'import sys ; print sys.exec_prefix'`
+		  changequote(<<, >>)dnl
+		  PY_VERSION=`$python_prog -c 'import sys ; print sys.version[0:3]'`
+		  broken_py_initialize=`$python_prog -c \
+'import sys
+if int(sys.version[0]) < 2:
+    print "yes"
+else:
+    print "no"'`
+		  changequote([, ])dnl
+	  	  if test "x$broken_py_initialize" = "xyes"; then
+			  AC_MSG_RESULT(no)
+			  python_val=false
+			  python_msg="NO.  Python version is too old."
+		  else	
+			  AC_MSG_RESULT(yes)
+		  fi
+	fi
+	if $python_val; then
+		  AC_MSG_CHECKING(Look for $PY_PREFIX/include/python$PY_VERSION/Python.h)
+		  if test -f $PY_PREFIX/include/python$PY_VERSION/Python.h; then
+			  AC_MSG_RESULT(yes)
+			  PY_LIBS="python$PY_VERSION"
+			  PY_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
+			  PY_CFLAGS="-I$PY_PREFIX/include/python$PY_VERSION"
+			  PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python$PY_VERSION/config/Makefile"
+			  PY_LOCALMODLIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE`
+			  PY_BASEMODLIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE`
+			  PY_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PY_MAKEFILE`
+			  PY_EXTRA_LIBS="$PY_LOCALMODLIBS $PY_BASEMODLIBS $PY_OTHER_LIBS"
+			  AC_SUBST(PY_LIBS)
+			  AC_SUBST(PY_LIB_LOC)
+			  AC_SUBST(PY_CFLAGS)
+			  AC_SUBST(PY_EXTRA_LIBS)
+		  else
+			  AC_MSG_RESULT(no)
+			  python_val=false
+		  fi
+	fi
+	if $python_val; then
+		AC_MSG_CHECKING(if we can build a shared library depending on libpython)
+		rm -rf testpython
+		mkdir testpython
+		cd testpython
+		cat > testpython.c <<EOF
+#include <Python.h>
+int testpython (void)
+{
+Py_Exit (0);
+}
+EOF
+		if /bin/sh ../libtool --mode=compile ${CC} $PY_CFLAGS -c testpython.c >/dev/null 2>&1 && \
+		   /bin/sh ../libtool --mode=link ${CC} -o testpython.la -rpath `pwd` -module -avoid-version $PY_LIB_LOC testpython.lo -l$PY_LIBS $PY_EXTRA_LIBS >/dev/null 2>&1 && \
+		   grep 'dlname.*testpython' testpython.la >/dev/null 2>&1; then
+			AC_MSG_RESULT(yes)
+			python_msg="yes"
+		else
+			AC_MSG_RESULT(no)
+			python_val=false
+			python_msg="unable to link to python"
+		fi
+		cd ..
+		rm -rf testpython
+	fi
+	AM_CONDITIONAL(WITH_PYTHON, $python_val)
+else
+	AC_MSG_ERROR(you need to have python installed !)
+fi
+
 dnl check for GStreamer
 GST_MAJORMINOR=0.8
 AC_SUBST(GST_MAJORMINOR)
Index: gst/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gst-python/gst/Makefile.am,v
retrieving revision 1.36.2.3
diff -u -3 -p -r1.36.2.3 Makefile.am
--- gst/Makefile.am	2 May 2005 23:32:31 -0000	1.36.2.3
+++ gst/Makefile.am	16 May 2005 14:06:30 -0000
@@ -76,6 +76,18 @@ CLEANFILES += interfaces.c
 EXTRA_DIST += $(INTERFACES_DEFS) $(INTERFACES_OVERRIDES) 
 interfaces.c: $(INTERFACES_DEFS) $(INTERFACES_OVERRIDES) $(GEN_FILES)
 
+# plugin that loads Python code
+PYTHON_LIBS = 			\
+ 	-l$(PY_LIBS)		\
+ 	$(PY_OTHER_LIBS)	\
+ 	$(PY_EXTRA_LIBS)
+plugindir = $(libdir)/gstreamer-$(GST_MAJORMINOR)
+plugin_LTLIBRARIES = libgstpython.la
+libgstpython_la_SOURCES = gstpythonplugin.c
+libgstpython_la_CFLAGS = $(common_cflags) $(PY_CFLAGS) -DGST_PLUGINDIR=\"$(plugindir)\"
+libgstpython_la_LIBADD = $(common_libadd) $(PY_LIB_LOC)
+libgstpython_la_LDFLAGS = $(common_ldflags) -avoid-version -module $(PYTHON_LIBS)
+
 .defs.c: 
 	(cd $(srcdir) \
 	&& $(PYGTK_CODEGEN) \
--- /dev/null	2005-04-25 17:55:46.827505992 +0200
+++ gst/gstpythonplugin.c	2005-05-16 16:05:37.000000000 +0200
@@ -0,0 +1,140 @@
+/* gst-python
+ * Copyright (C) 2005 Benjamin Otte <otte@gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ * 
+ * Author: David I. Lehn <dlehn@users.sourceforge.net>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* include this first, before NO_IMPORT_PYGOBJECT is defined */
+#include <pygobject.h>
+#include <gst/gst.h>
+#include "common.h"
+
+/* FIXME */
+#define GST_PACKAGE "gst-python"
+#define GST_ORIGIN "http://gstreamer.freedesktop.org"
+
+static PyObject *element;
+
+static gboolean
+gst_python_plugin_load_file (const char *name)
+{
+  PyObject *main_module, *main_locals;
+  PyObject *module;
+  
+  GST_DEBUG ("loading plugin %s", name);
+	      
+  main_module = PyImport_AddModule("__main__");
+  if (main_module == NULL) {
+    GST_WARNING ("Could not get __main__, ignoring plugin %s", name);
+    PyErr_Print ();
+    PyErr_Clear ();
+    return FALSE;
+  }
+  
+  main_locals = PyModule_GetDict(main_module);
+  module = PyImport_ImportModuleEx((char *) name, main_locals, main_locals, NULL);
+  if (!module) {
+    GST_WARNING ("Could not load module, ignoring plugin %s", name);
+    PyErr_Print ();
+    PyErr_Clear ();
+    return FALSE;
+  }
+  return TRUE;
+}
+
+static gboolean
+gst_python_plugin_load (void)
+{
+  PyObject *sys_path;
+  GDir *dir;
+  const gchar *file;
+  GError *error = NULL;
+  gboolean ret = TRUE;
+
+  sys_path = PySys_GetObject("path");
+  PyList_Insert(sys_path, 0, PyString_FromString(GST_PLUGINDIR "/python"));
+  
+  dir = g_dir_open (GST_PLUGINDIR "/python", 0, &error);
+  if (!dir) {
+    /*retval should probably be depending on error, but since we ignore it... */
+    GST_WARNING ("Couldn't open Python plugin dir: %s", error->message);
+    g_error_free (error);
+    return FALSE;
+  }
+  while ((file = g_dir_read_name (dir))) {
+    if (g_str_has_suffix (file, ".py")) {
+      gsize len = strlen(file) - 3;
+      gchar *name = g_strndup (file, len);
+      ret &= gst_python_plugin_load_file (name);
+      g_free (name);
+    }
+  }
+  return ret;
+}
+
+static gboolean
+plugin_init (GstPlugin *plugin)
+{
+  PyObject *pygst, *dict, *pyplugin;
+  gboolean we_initialized = FALSE;
+
+  if (!Py_IsInitialized()) {
+    /* set the correct plugin for registering stuff */
+    Py_Initialize();
+    we_initialized = TRUE;
+  }
+	
+  pygst = PyImport_ImportModule("gst");
+  if (!pygst) {
+    GST_ERROR ("no pygst!");
+    PyErr_Print ();
+    PyErr_Clear ();
+    return FALSE;
+  }
+  if (we_initialized) {
+    pyplugin = pyg_boxed_new (GST_TYPE_PLUGIN, plugin, FALSE, FALSE);
+    if (!pyplugin || PyModule_AddObject (pygst, "__plugin__", pyplugin) != 0) {
+      g_warning ("Couldn't set plugin");
+      Py_DECREF (pyplugin);
+    }
+  }
+  
+  dict = PyModule_GetDict(pygst);
+  if (!dict) {
+    GST_ERROR ("no dict?!");
+    return FALSE;
+  }
+  element = PyDict_GetItemString (dict, "Element");
+  if (!element) {
+    GST_ERROR ("Couldn't find gst.Element");
+    return FALSE;
+  }
+  
+  gst_python_plugin_load ();
+  return TRUE;
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+    GST_VERSION_MINOR,
+    "python",
+    "a collection of games to showcase features",
+    plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
