diff -ruN lash-pristine/Makefile.am lash-patched/Makefile.am --- lash-pristine/Makefile.am 2006-03-27 05:00:46.000000000 +0300 +++ lash-patched/Makefile.am 2007-04-09 03:56:11.000000000 +0300 @@ -1,4 +1,4 @@ -SUBDIRS = m4 docs lash liblash lashd clients icons +SUBDIRS = m4 docs lash liblash lashd clients icons pylash pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = lash-1.0.pc diff -ruN lash-pristine/acinclude.m4 lash-patched/acinclude.m4 --- lash-pristine/acinclude.m4 1970-01-01 02:00:00.000000000 +0200 +++ lash-patched/acinclude.m4 2007-04-09 03:56:11.000000000 +0300 @@ -0,0 +1,59 @@ +AC_DEFUN([AC_PROG_SWIG],[ + AC_PATH_PROG([SWIG],[swig]) + if test -z "$SWIG" ; then + AC_MSG_WARN([cannot find 'swig' program. You should look at http://www.swig.org]) + SWIG='echo "Error: SWIG is not installed. You should look at http://www.swig.org" ; false' + elif test -n "$1" ; then + AC_MSG_CHECKING([for SWIG version]) + [swig_version=`$SWIG -version 2>&1 | grep 'SWIG Version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`] + AC_MSG_RESULT([$swig_version]) + if test -n "$swig_version" ; then + # Calculate the required version number components + [required=$1] + [required_major=`echo $required | sed 's/[^0-9].*//'`] + if test -z "$required_major" ; then + [required_major=0] + fi + [required=`echo $required | sed 's/[0-9]*[^0-9]//'`] + [required_minor=`echo $required | sed 's/[^0-9].*//'`] + if test -z "$required_minor" ; then + [required_minor=0] + fi + [required=`echo $required | sed 's/[0-9]*[^0-9]//'`] + [required_patch=`echo $required | sed 's/[^0-9].*//'`] + if test -z "$required_patch" ; then + [required_patch=0] + fi + # Calculate the available version number components + [available=$swig_version] + [available_major=`echo $available | sed 's/[^0-9].*//'`] + if test -z "$available_major" ; then + [available_major=0] + fi + [available=`echo $available | sed 's/[0-9]*[^0-9]//'`] + [available_minor=`echo $available | sed 's/[^0-9].*//'`] + if test -z "$available_minor" ; then + [available_minor=0] + fi + [available=`echo $available | sed 's/[0-9]*[^0-9]//'`] + [available_patch=`echo $available | sed 's/[^0-9].*//'`] + if test -z "$available_patch" ; then + [available_patch=0] + fi + if test $available_major -ne $required_major \ + -o $available_minor -ne $required_minor \ + -o $available_patch -lt $required_patch ; then + AC_MSG_WARN([SWIG version >= $1 is required. You have $swig_version. You should look at http://www.swig.org]) + SWIG='echo "Error: SWIG version >= $1 is required. You have '"$swig_version"'. You should look at http://www.swig.org" ; false' + else + AC_MSG_NOTICE([SWIG executable is '$SWIG']) + SWIG_LIB=`$SWIG -swiglib` + AC_MSG_NOTICE([SWIG library directory is '$SWIG_LIB']) + fi + else + AC_MSG_WARN([cannot determine SWIG version]) + SWIG='echo "Error: Cannot determine SWIG version. You should look at http://www.swig.org" ; false' + fi + fi + AC_SUBST([SWIG_LIB]) +]) diff -ruN lash-pristine/configure.ac lash-patched/configure.ac --- lash-pristine/configure.ac 2007-04-06 05:03:38.000000000 +0300 +++ lash-patched/configure.ac 2007-04-09 03:56:11.000000000 +0300 @@ -151,6 +151,22 @@ fi AM_CONDITIONAL(HAVE_READLINE, test "x$lash_readline" != "xno") +################ +### pylash ### +################ + +AM_PATH_PYTHON() + +build_pylash=no + +AC_MSG_RESULT([$PYTHON]) + +if test "$PYTHON"; then + AC_PROG_SWIG(1.3.31) + if test "$SWIG_LIB" ; then + build_pylash=yes + fi +fi ###################### ### --enable-debug ### @@ -239,6 +255,7 @@ AC_CONFIG_FILES([clients/save_button/Makefile]) AC_CONFIG_FILES([clients/panel/Makefile]) AC_CONFIG_FILES([icons/Makefile]) +AC_CONFIG_FILES([pylash/Makefile]) AC_OUTPUT @@ -268,6 +285,7 @@ Gtk support: $lash_gtk2 Debugging output: $lash_debug Building manual: $lash_texi2html + Building pylash: $build_pylash CFLAGS: $CFLAGS diff -ruN lash-pristine/pylash/Makefile.am lash-patched/pylash/Makefile.am --- lash-pristine/pylash/Makefile.am 1970-01-01 02:00:00.000000000 +0200 +++ lash-patched/pylash/Makefile.am 2007-04-09 03:56:28.000000000 +0300 @@ -0,0 +1,37 @@ +# +# Copyright (C) 2007 Nedko Arnaudov +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License +# +# 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 St, Fifth Floor, Boston, MA 02110-1301 USA. +# + +include $(top_srcdir)/common.am + +pkgpyexecdir = $(pythondir) + +pkgpyexec_LTLIBRARIES = _lash.la + +INCLUDES = $(PYTHON_INCLUDES) + +_lash_la_LDFLAGS = -module -avoid-version ../liblash/liblash.la + +_lash_la_SOURCES = lash.c lash.h +BUILT_SOURCES = lash_wrap.c + +pkgpyexec_SCRIPTS = lash.py + +CLEANFILES = lash_wrap.c lash.py lash.pyc zynjacku.defs +EXTRA_DIST = test.py lash.i + +lash_wrap.c lash.py: lash.i lash.h + $(SWIG) -o lash_wrap.c -I$(top_srcdir) -python $(top_srcdir)/$(subdir)/lash.i diff -ruN lash-pristine/pylash/lash.c lash-patched/pylash/lash.c --- lash-pristine/pylash/lash.c 1970-01-01 02:00:00.000000000 +0200 +++ lash-patched/pylash/lash.c 2007-04-09 03:56:28.000000000 +0300 @@ -0,0 +1,29 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/***************************************************************************** + * + * Python bindings for LASH + * + * Copyright (C) 2006 Nedko Arnaudov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA. + * + *****************************************************************************/ + +#include "lash/lash.h" + +lash_client_t * init(int * argc, char *** argv, const char * client_class, int client_flags) +{ + return lash_init(lash_extract_args(argc, argv), client_class, client_flags, LASH_PROTOCOL_VERSION); +} diff -ruN lash-pristine/pylash/lash.h lash-patched/pylash/lash.h --- lash-pristine/pylash/lash.h 1970-01-01 02:00:00.000000000 +0200 +++ lash-patched/pylash/lash.h 2007-04-09 03:56:28.000000000 +0300 @@ -0,0 +1,29 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/***************************************************************************** + * + * Python bindings for LASH + * + * Copyright (C) 2006 Nedko Arnaudov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA. + * + *****************************************************************************/ + +#ifndef LASH_H__74601D15_FF3A_4086_B6F6_8D626BBCD7A2__INCLUDED +#define LASH_H__74601D15_FF3A_4086_B6F6_8D626BBCD7A2__INCLUDED + +lash_client_t * init(int * argc, char *** argv, const char * client_class, int client_flags); + +#endif /* #ifndef LASH_H__74601D15_FF3A_4086_B6F6_8D626BBCD7A2__INCLUDED */ diff -ruN lash-pristine/pylash/lash.i lash-patched/pylash/lash.i --- lash-pristine/pylash/lash.i 1970-01-01 02:00:00.000000000 +0200 +++ lash-patched/pylash/lash.i 2007-04-09 03:56:28.000000000 +0300 @@ -0,0 +1,135 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/***************************************************************************** + * + * Python bindings for LASH + * + * Copyright (C) 2006 Nedko Arnaudov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA. + * + *****************************************************************************/ + +#ifndef LASH_I__74601D15_FF3A_4086_B6F6_8D626BBCD7A2__INCLUDED +#define LASH_I__74601D15_FF3A_4086_B6F6_8D626BBCD7A2__INCLUDED + +#ifdef SWIG +%module lash + +%typemap(in) (int *argc, char ***argv) +{ + int i; + + if (!PyList_Check($input)) + { + PyErr_SetString(PyExc_ValueError, "Expecting a list"); + goto fail; + } + + $1 = (int *) malloc(sizeof(int)); + if ($1 == NULL) + { + PyErr_SetString(PyExc_ValueError, "malloc() failed."); + goto fail; + } + + *$1 = PyList_Size($input); + + $2 = (char ***) malloc(sizeof(char **)); + if ($2 == NULL) + { + PyErr_SetString(PyExc_ValueError, "malloc() failed."); + goto fail; + } + + *$2 = (char **) malloc((*$1+1)*sizeof(char *)); + if (*$2 == NULL) + { + PyErr_SetString(PyExc_ValueError, "malloc() failed."); + goto fail; + } + + for (i = 0; i < *$1; i++) + { + PyObject *s = PyList_GetItem($input,i); + if (!PyString_Check(s)) + { + PyErr_SetString(PyExc_ValueError, "List items must be strings"); + goto fail; + } + + (*$2)[i] = PyString_AsString(s); + } + + (*$2)[i] = 0; +} + +%typemap(argout) (int *argc, char ***argv) +{ + int i; + + for (i = 0; i < *$1; i++) + { + PyObject *s = PyString_FromString((*$2)[i]); + PyList_SetItem($input,i,s); + } + + while (i < PySequence_Size($input)) + { + PySequence_DelItem($input,i); + } +} + +%typemap(freearg) (int *argc, char ***argv) +{ + if ($1 != NULL) + { + //printf("freeing argc pointer storage\n"); + free($1); + $1 = NULL; + } + + if ($2 != NULL) + { + if (*$2 != NULL) + { + //printf("freeing array pointed by argv pointer storage\n"); + free(*$2); + } + + //printf("freeing argv pointer storage\n"); + free($2); + $1 = NULL; + } +} + +%{ +#include +#include +#include +#include +#include "lash.h" +typedef unsigned char * uuid_t_compat; +#define uuid_t uuid_t_compat +%} + +#endif + +%include +%include +%include +%include +%include + +#endif /* #ifndef LASH_I__74601D15_FF3A_4086_B6F6_8D626BBCD7A2__INCLUDED */ diff -ruN lash-pristine/pylash/test.py lash-patched/pylash/test.py --- lash-pristine/pylash/test.py 1970-01-01 02:00:00.000000000 +0200 +++ lash-patched/pylash/test.py 2007-04-09 03:56:28.000000000 +0300 @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# +# This file shows example usage of python bindings for LASH +# As such code here is public domain you can use it as you wish and in +# particular use this code as template for adding LASH support to your program. +# + +import sys +import time +import lash + +def lash_check_events(lash_client): + event = lash.lash_get_event(lash_client) + + while event: + print repr(event) + + event_type = lash.lash_event_get_type(event) + if event_type == lash.LASH_Quit: + print "LASH ordered quit." + return False + elif event_type == lash.LASH_Save_File: + print "LASH ordered to save data in directory %s" % lash.lash_event_get_string(event) + lash.lash_send_event(lash_client, event) + elif event_type == lash.LASH_Save_Data_Set: + print "LASH ordered to save data" + lash.lash_send_event(lash_client, event) + elif event_type == lash.LASH_Restore_Data_Set: + print "LASH ordered to restore data" + lash.lash_event_destroy(event) + elif event_type == lash.LASH_Restore_File: + print "LASH ordered to restore data from directory %s" % lash.lash_event_get_string(event) + lash.lash_event_destroy(event) + else: + print "Got unhandled LASH event, type " + str(event_type) + lash.lash_event_destroy(event) + return True + + event = lash.lash_get_event(lash_client) + + return True + +# sys.argv is modified by this call +lash_client = lash.init(sys.argv, "pylash test", lash.LASH_Config_Data_Set | lash.LASH_Terminal) + +print "Successfully connected to LASH server at " + lash.lash_get_server_name(lash_client) + +# Send our client name to server +lash_event = lash.lash_event_new_with_type(lash.LASH_Client_Name) +lash.lash_event_set_string(lash_event, "pylash test") +lash.lash_send_event(lash_client, lash_event) + +# loop until we receive quit order from LASH server +while lash_check_events(lash_client): + time.sleep(1)