diff options
| author | Sebastien Estienne <sebastien.estienne@gmail.com> | 2005-08-02 23:14:13 +0000 | 
|---|---|---|
| committer | Sebastien Estienne <sebastien.estienne@gmail.com> | 2005-08-02 23:14:13 +0000 | 
| commit | 1a912326734243e57a461c48131c1a0402318b5a (patch) | |
| tree | 5682d5a2f149712d775ac5f9cb05ead614d889a5 | |
| parent | 4a26b34ce1c7c2b1f0b65028f5d096939ab9b164 (diff) | |
* add avahi-utils in autoconf
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@211 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
| -rw-r--r-- | Makefile.am | 4 | ||||
| -rw-r--r-- | avahi-utils/Makefile.am | 6 | ||||
| -rw-r--r-- | avahi-utils/SimpleGladeApp.py | 122 | ||||
| -rwxr-xr-x | avahi-utils/avahi-discover.in (renamed from avahi-utils/avahi-discover) | 7 | ||||
| -rwxr-xr-x | avahi-utils/avahi-dump-all.in (renamed from avahi-utils/avahi-dump-all) | 2 | ||||
| -rwxr-xr-x | avahi-utils/avahi-publish-address.in (renamed from avahi-utils/avahi-publish-address) | 2 | ||||
| -rwxr-xr-x | avahi-utils/avahi-publish-service.in (renamed from avahi-utils/avahi-publish-service) | 2 | ||||
| -rw-r--r-- | avahi-utils/avahi/Makefile.am | 4 | ||||
| -rw-r--r-- | avahi-utils/avahi/SimpleGladeApp.py | 341 | ||||
| -rw-r--r-- | avahi-utils/avahi/__init__.py (renamed from avahi-utils/avahi.py) | 0 | ||||
| -rw-r--r-- | configure.ac | 10 | ||||
| -rwxr-xr-x | py-compile | 92 | 
12 files changed, 461 insertions, 131 deletions
diff --git a/Makefile.am b/Makefile.am index 6652d1a..4d25b3c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,11 +19,11 @@  include aminclude.am  EXTRA_DIST = bootstrap.sh LICENSE $(DX_CONFIG) -SUBDIRS = avahi-common avahi-core avahi-discover avahi-client avahi-daemon initscript avahi-dnsconfd +SUBDIRS = avahi-common avahi-core avahi-discover avahi-client avahi-daemon initscript avahi-dnsconfd avahi-utils  pkgconfigdir = $(libdir)/pkgconfig  pkgconfig_DATA = avahi-core.pc  MOSTLYCLEANFILES = $(DX_CLEANFILES) -.PHONY: distcleancheck +#.PHONY: distcleancheck diff --git a/avahi-utils/Makefile.am b/avahi-utils/Makefile.am new file mode 100644 index 0000000..ac8686e --- /dev/null +++ b/avahi-utils/Makefile.am @@ -0,0 +1,6 @@ +SUBDIRS=avahi + +avahiscriptsdir = $(bindir) +avahiscripts_SCRIPTS = avahi-publish-address avahi-publish-service avahi-dump-all + +EXTRA_DIST = $(avahiscripts_SCRIPTS) diff --git a/avahi-utils/SimpleGladeApp.py b/avahi-utils/SimpleGladeApp.py deleted file mode 100644 index 6d204e3..0000000 --- a/avahi-utils/SimpleGladeApp.py +++ /dev/null @@ -1,122 +0,0 @@ -# SimpleGladeApp.py -# Module that provides an object oriented abstraction to pygtk and libglade. -# Copyright (C) 2004 Sandino Flores Moreno - -# This library 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.1 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser 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 - -try: -        import os -        import sys -        import gtk -        import gtk.glade -        import weakref -except ImportError: -        print "Error importing pygtk2 and pygtk2-libglade" -        sys.exit(1) - -class SimpleGladeApp(dict): -        def __init__(self, glade_filename, main_widget_name=None, domain=None, **kwargs): -                if os.path.isfile(glade_filename): -                        self.glade_path = glade_filename -                else: -                        glade_dir = os.path.split( sys.argv[0] )[0] -                        self.glade_path = os.path.join(glade_dir, glade_filename) -                for key, value in kwargs.items(): -                        try: -                                setattr(self, key, weakref.proxy(value) ) -                        except TypeError: -                                setattr(self, key, value) -                self.glade = None -                gtk.glade.set_custom_handler(self.custom_handler) -                self.glade = gtk.glade.XML(self.glade_path, main_widget_name, domain) -                if main_widget_name: -                        self.main_widget = self.glade.get_widget(main_widget_name) -                else: -                        self.main_widget = None -                self.signal_autoconnect() -                self.new() - -        def signal_autoconnect(self): -                signals = {} -                for attr_name in dir(self): -                        attr = getattr(self, attr_name) -                        if callable(attr): -                                signals[attr_name] = attr -                self.glade.signal_autoconnect(signals) - -        def custom_handler(self, -                        glade, function_name, widget_name, -                        str1, str2, int1, int2): -                if hasattr(self, function_name): -                        handler = getattr(self, function_name) -                        return handler(str1, str2, int1, int2) - -        def __getattr__(self, name): -                if name in self: -                        data = self[name] -                        return data -                else: -                        widget = self.glade.get_widget(name) -                        if widget != None: -                                self[name] = widget -                                return widget -                        else: -                                raise AttributeError, name - -        def __setattr__(self, name, value): -                self[name] = value - -        def new(self): -                pass - -        def on_keyboard_interrupt(self): -                pass - -        def gtk_widget_show(self, widget, *args): -                widget.show() - -        def gtk_widget_hide(self, widget, *args): -                widget.hide() - -        def gtk_widget_grab_focus(self, widget, *args): -                widget.grab_focus() - -        def gtk_widget_destroy(self, widget, *args): -                widget.destroy() - -        def gtk_window_activate_default(self, widget, *args): -                widget.activate_default() - -        def gtk_true(self, *args): -                return gtk.TRUE - -        def gtk_false(self, *args): -                return gtk.FALSE - -        def gtk_main_quit(self, *args): -                gtk.main_quit() - -        def main(self): -                gtk.main() - -        def quit(self): -                gtk.main_quit() - -        def run(self): -                try: -                        self.main() -                except KeyboardInterrupt: -                        self.on_keyboard_interrupt() diff --git a/avahi-utils/avahi-discover b/avahi-utils/avahi-discover.in index 9ebae71..9734ae6 100755 --- a/avahi-utils/avahi-discover +++ b/avahi-utils/avahi-discover.in @@ -1,14 +1,13 @@ -#!/usr/bin/python2.4 +#!/usr/bin/env @PYTHON@  # -*-python-*-  # $Id$  import os  import gtk  import gobject -from SimpleGladeApp import SimpleGladeApp  import avahi, dbus, gobject, sys - +from avahi.SimpleGladeApp import SimpleGladeApp  try:      import dbus.glib @@ -19,7 +18,7 @@ service_type_browsers = {}  service_browsers = {} -glade_dir = "../avahi-discover/" +glade_dir = "@prefix@/share/@PACKAGE@/interfaces"  class Main_window(SimpleGladeApp):      def __init__(self, path="avahi-discover.glade", root="main_window", domain=None, **kwargs): diff --git a/avahi-utils/avahi-dump-all b/avahi-utils/avahi-dump-all.in index 035f581..6e27240 100755 --- a/avahi-utils/avahi-dump-all +++ b/avahi-utils/avahi-dump-all.in @@ -1,4 +1,4 @@ -#!/usr/bin/python2.4 +#!/usr/bin/env @PYTHON@  # -*-python-*-  # $Id$  diff --git a/avahi-utils/avahi-publish-address b/avahi-utils/avahi-publish-address.in index d03f928..43921e8 100755 --- a/avahi-utils/avahi-publish-address +++ b/avahi-utils/avahi-publish-address.in @@ -1,4 +1,4 @@ -#!/usr/bin/python2.4 +#!/usr/bin/env @PYTHON@  # -*-python-*-  # $Id$ diff --git a/avahi-utils/avahi-publish-service b/avahi-utils/avahi-publish-service.in index d823f14..e6bb39c 100755 --- a/avahi-utils/avahi-publish-service +++ b/avahi-utils/avahi-publish-service.in @@ -1,4 +1,4 @@ -#!/usr/bin/python2.4 +#!/usr/bin/env @PYTHON@  # -*-python-*-  # $Id$ diff --git a/avahi-utils/avahi/Makefile.am b/avahi-utils/avahi/Makefile.am new file mode 100644 index 0000000..357d3dc --- /dev/null +++ b/avahi-utils/avahi/Makefile.am @@ -0,0 +1,4 @@ +avahidir = $(pythondir)/avahi +avahi_PYTHON = __init__.py SimpleGladeApp.py + +EXTRA_DIST = $(avahi_PYTHON) diff --git a/avahi-utils/avahi/SimpleGladeApp.py b/avahi-utils/avahi/SimpleGladeApp.py new file mode 100644 index 0000000..90c598c --- /dev/null +++ b/avahi-utils/avahi/SimpleGladeApp.py @@ -0,0 +1,341 @@ +""" + SimpleGladeApp.py + Module that provides an object oriented abstraction to pygtk and libglade. + Copyright (C) 2004 Sandino Flores Moreno +""" + +# This library 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.1 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser 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 + +import os +import sys +import re + +import tokenize +import gtk +import gtk.glade +import weakref +import inspect + +__version__ = "1.0" +__author__ = 'Sandino "tigrux" Flores-Moreno' + +def bindtextdomain(app_name, locale_dir=None): +    """     +    Bind the domain represented by app_name to the locale directory locale_dir. +    It has the effect of loading translations, enabling applications for different +    languages. + +    app_name: +        a domain to look for translations, tipically the name of an application. + +    locale_dir: +        a directory with locales like locale_dir/lang_isocode/LC_MESSAGES/app_name.mo +        If omitted or None, then the current binding for app_name is used. +    """     +    try: +        import locale +        import gettext +        locale.setlocale(locale.LC_ALL, "") +        gtk.glade.bindtextdomain(app_name, locale_dir) +        gettext.install(app_name, locale_dir, unicode=1) +    except (IOError,locale.Error), e: +        print "Warning", app_name, e +        __builtins__.__dict__["_"] = lambda x : x + + +class SimpleGladeApp: + +    def __init__(self, path, root=None, domain=None, **kwargs): +        """ +        Load a glade file specified by glade_filename, using root as +        root widget and domain as the domain for translations. + +        If it receives extra named arguments (argname=value), then they are used +        as attributes of the instance. + +        path: +            path to a glade filename. +            If glade_filename cannot be found, then it will be searched in the +            same directory of the program (sys.argv[0]) + +        root: +            the name of the widget that is the root of the user interface, +            usually a window or dialog (a top level widget). +            If None or ommited, the full user interface is loaded. + +        domain: +            A domain to use for loading translations. +            If None or ommited, no translation is loaded. + +        **kwargs: +            a dictionary representing the named extra arguments. +            It is useful to set attributes of new instances, for example: +                glade_app = SimpleGladeApp("ui.glade", foo="some value", bar="another value") +            sets two attributes (foo and bar) to glade_app. +        """         +        if os.path.isfile(path): +            self.glade_path = path +        else: +            glade_dir = os.path.dirname( sys.argv[0] ) +            self.glade_path = os.path.join(glade_dir, path) +        for key, value in kwargs.items(): +            try: +                setattr(self, key, weakref.proxy(value) ) +            except TypeError: +                setattr(self, key, value) +        self.glade = None +        self.install_custom_handler(self.custom_handler) +        self.glade = self.create_glade(self.glade_path, root, domain) +        if root: +            self.main_widget = self.get_widget(root) +        else: +            self.main_widget = None +        self.normalize_names() +        self.add_callbacks(self) +        self.new() + +    def __repr__(self): +        class_name = self.__class__.__name__ +        if self.main_widget: +            root = gtk.Widget.get_name(self.main_widget) +            repr = '%s(path="%s", root="%s")' % (class_name, self.glade_path, root) +        else: +            repr = '%s(path="%s")' % (class_name, self.glade_path) +        return repr + +    def new(self): +        """ +        Method called when the user interface is loaded and ready to be used. +        At this moment, the widgets are loaded and can be refered as self.widget_name +        """ +        pass + +    def add_callbacks(self, callbacks_proxy): +        """ +        It uses the methods of callbacks_proxy as callbacks. +        The callbacks are specified by using: +            Properties window -> Signals tab +            in glade-2 (or any other gui designer like gazpacho). + +        Methods of classes inheriting from SimpleGladeApp are used as +        callbacks automatically. + +        callbacks_proxy: +            an instance with methods as code of callbacks. +            It means it has methods like on_button1_clicked, on_entry1_activate, etc. +        """         +        self.glade.signal_autoconnect(callbacks_proxy) + +    def normalize_names(self): +        """ +        It is internally used to normalize the name of the widgets. +        It means a widget named foo:vbox-dialog in glade +        is refered self.vbox_dialog in the code. + +        It also sets a data "prefixes" with the list of +        prefixes a widget has for each widget. +        """ +        for widget in self.get_widgets(): +            widget_name = gtk.Widget.get_name(widget) +            prefixes_name_l = widget_name.split(":") +            prefixes = prefixes_name_l[ : -1] +            widget_api_name = prefixes_name_l[-1] +            widget_api_name = "_".join( re.findall(tokenize.Name, widget_api_name) ) +            gtk.Widget.set_name(widget, widget_api_name) +            if hasattr(self, widget_api_name): +                raise AttributeError("instance %s already has an attribute %s" % (self,widget_api_name)) +            else: +                setattr(self, widget_api_name, widget) +                if prefixes: +                    gtk.Widget.set_data(widget, "prefixes", prefixes) + +    def add_prefix_actions(self, prefix_actions_proxy): +        """ +        By using a gui designer (glade-2, gazpacho, etc) +        widgets can have a prefix in theirs names +        like foo:entry1 or foo:label3 +        It means entry1 and label3 has a prefix action named foo. + +        Then, prefix_actions_proxy must have a method named prefix_foo which +        is called everytime a widget with prefix foo is found, using the found widget +        as argument. + +        prefix_actions_proxy: +            An instance with methods as prefix actions. +            It means it has methods like prefix_foo, prefix_bar, etc. +        """         +        prefix_s = "prefix_" +        prefix_pos = len(prefix_s) + +        is_method = lambda t : callable( t[1] ) +        is_prefix_action = lambda t : t[0].startswith(prefix_s) +        drop_prefix = lambda (k,w): (k[prefix_pos:],w) + +        members_t = inspect.getmembers(prefix_actions_proxy) +        methods_t = filter(is_method, members_t) +        prefix_actions_t = filter(is_prefix_action, methods_t) +        prefix_actions_d = dict( map(drop_prefix, prefix_actions_t) ) + +        for widget in self.get_widgets(): +            prefixes = gtk.Widget.get_data(widget, "prefixes") +            if prefixes: +                for prefix in prefixes: +                    if prefix in prefix_actions_d: +                        prefix_action = prefix_actions_d[prefix] +                        prefix_action(widget) + +    def custom_handler(self, +            glade, function_name, widget_name, +            str1, str2, int1, int2): +        """ +        Generic handler for creating custom widgets, internally used to +        enable custom widgets (custom widgets of glade). + +        The custom widgets have a creation function specified in design time. +        Those creation functions are always called with str1,str2,int1,int2 as +        arguments, that are values specified in design time. + +        Methods of classes inheriting from SimpleGladeApp are used as +        creation functions automatically. + +        If a custom widget has create_foo as creation function, then the +        method named create_foo is called with str1,str2,int1,int2 as arguments. +        """ +        try: +            handler = getattr(self, function_name) +            return handler(str1, str2, int1, int2) +        except AttributeError: +            return None + +    def gtk_widget_show(self, widget, *args): +        """ +        Predefined callback. +        The widget is showed. +        Equivalent to widget.show() +        """ +        widget.show() + +    def gtk_widget_hide(self, widget, *args): +        """ +        Predefined callback. +        The widget is hidden. +        Equivalent to widget.hide() +        """ +        widget.hide() + +    def gtk_widget_grab_focus(self, widget, *args): +        """ +        Predefined callback. +        The widget grabs the focus. +        Equivalent to widget.grab_focus() +        """ +        widget.grab_focus() + +    def gtk_widget_destroy(self, widget, *args): +        """ +        Predefined callback. +        The widget is destroyed. +        Equivalent to widget.destroy() +        """ +        widget.destroy() + +    def gtk_window_activate_default(self, window, *args): +        """ +        Predefined callback. +        The default widget of the window is activated. +        Equivalent to window.activate_default() +        """ +        widget.activate_default() + +    def gtk_true(self, *args): +        """ +        Predefined callback. +        Equivalent to return True in a callback. +        Useful for stopping propagation of signals. +        """ +        return True + +    def gtk_false(self, *args): +        """ +        Predefined callback. +        Equivalent to return False in a callback. +        """ +        return False + +    def gtk_main_quit(self, *args): +        """ +        Predefined callback. +        Equivalent to self.quit() +        """ +        self.quit() + +    def main(self): +        """ +        Starts the main loop of processing events. +        The default implementation calls gtk.main() + +        Useful for applications that needs a non gtk main loop. +        For example, applications based on gstreamer needs to override +        this method with gst.main() + +        Do not directly call this method in your programs. +        Use the method run() instead. +        """ +        gtk.main() + +    def quit(self): +        """ +        Quit processing events. +        The default implementation calls gtk.main_quit() +         +        Useful for applications that needs a non gtk main loop. +        For example, applications based on gstreamer needs to override +        this method with gst.main_quit() +        """ +        gtk.main_quit() + +    def run(self): +        """ +        Starts the main loop of processing events checking for Control-C. + +        The default implementation checks wheter a Control-C is pressed, +        then calls on_keyboard_interrupt(). + +        Use this method for starting programs. +        """ +        try: +            self.main() +        except KeyboardInterrupt: +            self.on_keyboard_interrupt() + +    def on_keyboard_interrupt(self): +        """ +        This method is called by the default implementation of run() +        after a program is finished by pressing Control-C. +        """ +        pass + +    def install_custom_handler(self, custom_handler): +        gtk.glade.set_custom_handler(custom_handler) + +    def create_glade(self, glade_path, root, domain): +        return gtk.glade.XML(self.glade_path, root, domain) + +    def get_widget(self, widget_name): +        return self.glade.get_widget(widget_name) + +    def get_widgets(self): +        return self.glade.get_widget_prefix("")         diff --git a/avahi-utils/avahi.py b/avahi-utils/avahi/__init__.py index 1e2761c..1e2761c 100644 --- a/avahi-utils/avahi.py +++ b/avahi-utils/avahi/__init__.py diff --git a/configure.ac b/configure.ac index e162452..29182ef 100644 --- a/configure.ac +++ b/configure.ac @@ -216,6 +216,8 @@ avahi_socket="${avahi_runtime_dir}/avahi-daemon/socket"  AC_SUBST(avahi_runtime_dir)  AC_SUBST(avahi_socket) +AM_PATH_PYTHON(2.2) +  AC_CONFIG_FILES([  Makefile   avahi-core.pc  @@ -230,6 +232,12 @@ initscript/Debian/Makefile  initscript/Gentoo/Makefile  initscript/SUSE/Makefile  avahi-dnsconfd/Makefile +avahi-utils/Makefile +avahi-utils/avahi/Makefile +avahi-utils/avahi-dump-all +avahi-utils/avahi-publish-service +avahi-utils/avahi-publish-address +avahi-utils/avahi-discover  ])  AC_OUTPUT @@ -243,6 +251,8 @@ echo "      dbus-1 version:         `pkg-config dbus-1 --modversion`      compiler:               ${CC}      cflags:                 ${CFLAGS} +    Enable Gtk:             ${ENABLE_GTK} +    Enable Dbus:            ${ENABLE_DBUS}      Linux Distro:           ${with_distro}      User for Avahi:         ${AVAHI_USER}      Group for Avahi:        ${AVAHI_GROUP} diff --git a/py-compile b/py-compile new file mode 100755 index 0000000..4c84b67 --- /dev/null +++ b/py-compile @@ -0,0 +1,92 @@ +#!/bin/sh + +# py-compile - Compile a Python program +# Copyright 2000, 2001 Free Software Foundation, Inc. + +# 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, 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., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# called as "py-compile [--basedir DIR] PY_FILES ... + +if [ -z "$PYTHON" ]; then +  PYTHON=python +fi + +basedir= + +case "$1" in +    --basedir) +	basedir=$2 +	shift 2 +	;; +    --help) +	echo "Usage: py-compile [--basedir DIR] PY_FILES ..." +	echo "Byte compile some python scripts.  This should be performed" +	echo "after they have been moved to the final installation location" +	exit 0 +	;; +    --version) +	echo "py-compile version 0.0" +	exit 0 +	;; +esac + +if [ $# = 0 ]; then +    echo "No files given to $0" 1>&2 +    exit 1 +fi + +# if basedir was given, then it should be prepended to filenames before +# byte compilation. +if [ -z "$basedir" ]; then +    trans="path = file" +else +    trans="path = os.path.join('$basedir', file)" +fi + +$PYTHON -c " +import sys, os, string, py_compile + +files = '''$*''' +print 'Byte-compiling python modules...' +for file in string.split(files): +    $trans +    if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'): +	continue +    print file, +    sys.stdout.flush() +    py_compile.compile(path) +print" || exit $? + +# this will fail for python < 1.5, but that doesn't matter ... +$PYTHON -O -c " +import sys, os, string, py_compile + +files = '''$*''' +print 'Byte-compiling python modules (optimized versions) ...' +for file in string.split(files): +    $trans +    if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'): +	continue +    print file, +    sys.stdout.flush() +    py_compile.compile(path) +print" 2>/dev/null || : +  | 
