From 5ce17adcb1ff31ffdc2618fcf4788beecc1e1ff8 Mon Sep 17 00:00:00 2001 From: Sebastien Estienne Date: Sat, 19 Nov 2005 00:33:52 +0000 Subject: * added a the begining of a proper plugin architecture git-svn-id: file:///home/lennart/svn/public/service-discovery-applet/trunk@80 3be567f1-68ff-0310-b24a-ad7cc433fd2f --- Makefile.am | 2 +- actions/Makefile.am | 2 - actions/services/Makefile.am | 16 --- actions/services/__init__.py.in | 232 ---------------------------------------- actions/services/_ssh_tcp.py | 95 ---------------- configure.ac | 10 +- plugins/Makefile.am | 8 ++ plugins/gnometerminal.py | 126 ++++++++++++++++++++++ plugins/nautilus.py | 48 +++++++++ po/POTFILES.in | 4 +- src/Makefile.am | 4 +- src/modules/Makefile.am | 24 +++++ src/modules/__init__.py | 12 +++ src/modules/pluginloader.py.in | 46 ++++++++ src/modules/pluginutils.py | 49 +++++++++ src/service-discovery-applet.in | 12 ++- 16 files changed, 331 insertions(+), 359 deletions(-) delete mode 100644 actions/Makefile.am delete mode 100644 actions/services/Makefile.am delete mode 100755 actions/services/__init__.py.in delete mode 100644 actions/services/_ssh_tcp.py create mode 100644 plugins/Makefile.am create mode 100644 plugins/gnometerminal.py create mode 100644 plugins/nautilus.py create mode 100644 src/modules/Makefile.am create mode 100644 src/modules/__init__.py create mode 100644 src/modules/pluginloader.py.in create mode 100644 src/modules/pluginutils.py diff --git a/Makefile.am b/Makefile.am index 509188f..38eb740 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,8 +3,8 @@ SUBDIRS = \ src \ icons \ schemas \ - actions \ servers \ + plugins \ po EXTRA_DIST = README INSTALL AUTHORS COPYING TODO \ diff --git a/actions/Makefile.am b/actions/Makefile.am deleted file mode 100644 index a829c18..0000000 --- a/actions/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -SUBDIRS = \ - services \ No newline at end of file diff --git a/actions/services/Makefile.am b/actions/services/Makefile.am deleted file mode 100644 index 651a31e..0000000 --- a/actions/services/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -servicesdir = $(ACTIONSDIR)/services -services_SCRIPTS = \ - __init__.py - -__init__.py: __init__.py.in - sed \ - -e 's,@PYTHON\@,$(PYTHON),g' \ - -e 's,@GETTEXT_PACKAGE\@,$(GETTEXT_PACKAGE),g' \ - -e 's,@LOCALEDIR\@,$(LOCALEDIR),g' \ - $< > $@ - chmod +x $@ - - -EXTRA_DIST = __init__.py.in - -CLEANFILES = $(services_SCRIPTS) diff --git a/actions/services/__init__.py.in b/actions/services/__init__.py.in deleted file mode 100755 index fb6d824..0000000 --- a/actions/services/__init__.py.in +++ /dev/null @@ -1,232 +0,0 @@ -#!@PYTHON@ -# -*- coding: UTF-8 -*- -# -*- python -*- -# Copyright (C) 2005 by Sebastien Estienne -# -# This file may be distributed and/or modified under the terms of -# the GNU General Public License version 2 as published by -# the Free Software Foundation. -# This file is distributed without any warranty; without even the implied -# warranty of merchantability or fitness for a particular purpose. -# See "COPYING" in the source distribution for more information. -# -# $id$ -# - -# BIG WARNING: -# this file is for the moment a big ugly quick hack -# I'm working on a clean plugin system to handle actions for service types -# it will hopefully appear in 0.3 -# this file is just an interim solution to give the same functionnaly as 0.1 - -try: - import gettext - gettext.bindtextdomain("@GETTEXT_PACKAGE@", "@LOCALEDIR@") - gettext.textdomain("@GETTEXT_PACKAGE@") - _ = gettext.gettext - import pygtk - pygtk.require('2.0') - import gtk - import os - import pwd - import subprocess - import gnome -except ImportError, e: - error_msg(_("A required python module is missing!\n%s") % (e)) - sys.exit() - -def pair_to_dict(l): - res = dict() - for el in l: - if "=" not in el: - res[el]='' - else: - tmp = el.split('=',1) - if len(tmp[0]) > 0: - res[tmp[0]] = tmp[1] - return res - - -def build_url(uri = "http", hostname="127.0.0.1", port = None, path = None, username = None, password = None): - if path and path != None: - if path[0] == "/": - path = path[1:] - else: - path = "" - - if username: - if password: - username="%s:%s@" % (username,password) - else: - username="%s@" % (username) - else: - username="" - if port and port != None: - hostname="%s:%i" % (hostname,port) - return "%s://%s%s/%s" % (uri,username,hostname,path) - -def get_txt_value(txts, txt): - if txts.has_key(txt): - return txts[txt] - else: - return None - - -def _http_tcp(name, hostname, address, port, txts): - path = get_txt_value(txts,"path") - username = get_txt_value(txts,"u") - password = get_txt_value(txts,"p") - url = build_url("http",address,port, path, username,password) - gnome.url_show(url) - -def _https_tcp(name, hostname, address, port, txts): - path = get_txt_value(txts,"path") - username = get_txt_value(txts,"u") - password = get_txt_value(txts,"p") - url = build_url("https",address,port, path, username,password) - gnome.url_show(url) - -def _webdav_tcp(name, hostname, address, port, txts): - path = get_txt_value(txts,"path") - username = get_txt_value(txts,"u") - password = get_txt_value(txts,"p") - url = build_url("dav",address,port, path, username,password) - gnome.url_show(url) - -def _webdavs_tcp(name, hostname, address, port, txts): - path = get_txt_value(txts,"path") - username = get_txt_value(txts,"u") - password = get_txt_value(txts,"p") - url = build_url("davs",address,port, path, username,password) - gnome.url_show(url) - -def _ftp_tcp(name, hostname, address, port, txts): - path = get_txt_value(txts,"path") - username = get_txt_value(txts,"u") - password = get_txt_value(txts,"p") - url = build_url("ftp",address,port, path, username,password) - gnome.url_show(url) - -def _sftpssh_tcp(name, hostname, address, port, txts): - path = get_txt_value(txts,"path") - username = get_txt_value(txts,"u") - password = get_txt_value(txts,"p") - url = build_url("sftp",address,port, path, username,password) - gnome.url_show(url) - -def enter_callback(widget, win): - win.response(gtk.RESPONSE_OK) - -def SshLogin(hostname, username = None): - global win - win = gtk.Dialog(_("SSH Connection"), None, - gtk.DIALOG_MODAL, - (gtk.STOCK_OK, gtk.RESPONSE_OK, - gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) - - vbox = gtk.VBox(False, 5) - win.vbox.pack_start(vbox, True, True, 0) - vbox.set_border_width(5) - - label = gtk.Label() - label.set_markup(_("Connecting to %s.\nPlease enter your login:") % (hostname)) - - vbox.pack_start(label, False, False, 0) - - # Create our entry - entry = gtk.Entry() - if username!= None: - entry.set_text(username) - entry.connect("activate", enter_callback, win) - vbox.pack_start(entry, False, False, 0) - - # Create the completion object - completion = gtk.EntryCompletion() - - # Assign the completion to the entry - entry.set_completion(completion) - - # Create a tree model and use it as the completion model - completion_model = __create_completion_model() - completion.set_model(completion_model) - - # Use model column 0 as the text column - completion.set_text_column(0) - - win.show_all() - if win.run() == gtk.RESPONSE_OK: - win.destroy() - return entry.get_text() - else: - win.destroy() - return None - -def __create_completion_model(): - ''' Creates a tree model containing the completions. - ''' - store = gtk.ListStore(str) - - iter = store.append() - store.set(iter, 0, "root") - - current_user = pwd.getpwuid(os.getuid())[0] - iter = store.append() - store.set(iter, 0, current_user) - - return store - -def _ssh_tcp(name, hostname, address, port, txts): - - if txts.has_key("u"): - username = SshLogin(name, txts["u"]) - else: - username = SshLogin(name) - - if username == None: - return - elif username != "": - sshline = "ssh -l %s -p %i %s" % (username, port, address) - else: - sshline = "ssh -p %i %s" % (port, address) - - cmdline = [] - cmdline.append("gnome-terminal") - cmdline.append("--tab") - cmdline.append("-t %s" % name) - cmdline.append("-e %s" % sshline) - pid = subprocess.Popen(cmdline).pid - -def handle(name, stype, hostname, address, port, txts): - if stype == "_http._tcp": - _http_tcp(name, hostname, address, port, txts) - return - if stype == "_https._tcp": - _https_tcp(name, hostname, address, port, txts) - return - if stype == "_ftp._tcp": - _ftp_tcp(name, hostname, address, port, txts) - return - if stype == "_ssh._tcp": - _ssh_tcp(name, hostname, address, port, txts) - return - if stype == "_sftp-ssh._tcp": - _sftpssh_tcp(name, hostname, address, port, txts) - return - if stype == "_webdav._tcp": - _webdav_tcp(name, hostname, address, port, txts) - return - if stype == "_webdavs._tcp": - _webdavs_tcp(name, hostname, address, port, txts) - return - -if __name__ == "__main__": - print build_url() - print build_url("ftp") - print build_url("https","www.google.com") - print build_url("https","www.google.com",80) - print build_url("https","www.google.com",80) - print build_url("https","www.google.com",80,"test") - print build_url("https","www.google.com",80,"/test") - print build_url("https","www.google.com",80,"/test", "user") - print build_url("https","www.google.com",0, "", None, "pass") - print build_url("https","www.google.com",80,"/test", "user", "pass") diff --git a/actions/services/_ssh_tcp.py b/actions/services/_ssh_tcp.py deleted file mode 100644 index 7660ea5..0000000 --- a/actions/services/_ssh_tcp.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/python - -import pygtk -pygtk.require('2.0') -import gtk -import os -import pwd - -def enter_callback(widget, win): - win.destroy() - -def SshLogin(hostname, username = None): - global win - win = gtk.Dialog("Ssh Connection", None, - gtk.DIALOG_MODAL, - (gtk.STOCK_OK, gtk.RESPONSE_OK, - gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) - - vbox = gtk.VBox(False, 5) - win.vbox.pack_start(vbox, True, True, 0) - vbox.set_border_width(5) - - label = gtk.Label() - label.set_markup("Connecting to %s.\nPlease enter your login:" % (hostname)) - - vbox.pack_start(label, False, False, 0) - - # Create our entry - entry = gtk.Entry() - if username!= None: - entry.set_text(username) - entry.connect("activate", enter_callback, win) - vbox.pack_start(entry, False, False, 0) - - # Create the completion object - completion = gtk.EntryCompletion() - - # Assign the completion to the entry - entry.set_completion(completion) - - # Create a tree model and use it as the completion model - completion_model = __create_completion_model() - completion.set_model(completion_model) - - # Use model column 0 as the text column - completion.set_text_column(0) - - win.show_all() - if win.run() == gtk.RESPONSE_OK: - win.destroy() - return entry.get_text() - else: - win.destroy() - return None - return entry.get_text() - -def __create_completion_model(): - ''' Creates a tree model containing the completions. - ''' - store = gtk.ListStore(str) - - iter = store.append() - store.set(iter, 0, "root") - - current_user = pwd.getpwuid(os.getuid())[0] - iter = store.append() - store.set(iter, 0, current_user) - - return store - -def _ssh_tcp(name, hostname, address, port, txts): - - if txts.has_key("u"): - username = SshLogin(name, txts["u"]) - else: - username = SshLogin(name) - - if username == None: - return - elif username != "": - sshline = "ssh -l %s -p %i %s" % (username, port, address) - else: - sshline = "ssh -p %i %s" % (port, address) - - cmdline = [] - cmdline.append("gnome-terminal") - cmdline.append("--tab") - cmdline.append("-t %s" % name) - cmdline.append("-e %s" % sshline) - pid = subprocess.Popen(cmdline).pid - -if __name__ == '__main__': -# res = SshLogin("localhost", "robert") -# print res - _ssh_tcp(name, hostname, address, port, txts) diff --git a/configure.ac b/configure.ac index 5969b26..36a33d4 100644 --- a/configure.ac +++ b/configure.ac @@ -21,10 +21,10 @@ AM_CHECK_PYMOD(avahi,,,[AC_MSG_ERROR(Could not find Python module avahi)]) # AM_CHECK_PYMOD(gnomeapplet,,,[AC_MSG_ERROR(Could not find Python module gnomeapplet)]) dnl ======================================================== -dnl Directory where services' actions will be installed +dnl Directory where services' plugins will be installed dnl ======================================================== -ACTIONSDIR="${datadir}/${PACKAGE}/actions/" -AC_SUBST(ACTIONSDIR) +PLUGINSDIR="${datadir}/${PACKAGE}/plugins/" +AC_SUBST(PLUGINSDIR) dnl ======================================================== dnl Directory where services' icons will be installed @@ -65,9 +65,9 @@ AC_CONFIG_FILES([ icons/48x48/Makefile schemas/Makefile servers/Makefile - actions/Makefile - actions/services/Makefile src/Makefile + src/modules/Makefile + plugins/Makefile po/Makefile.in ]) AC_OUTPUT diff --git a/plugins/Makefile.am b/plugins/Makefile.am new file mode 100644 index 0000000..37902fb --- /dev/null +++ b/plugins/Makefile.am @@ -0,0 +1,8 @@ +pluginsdir = $(PLUGINSDIR) + +plugins_DATA = \ + gnometerminal.py \ + nautilus.py + + +EXTRA_DIST = $(plugins_DATA) diff --git a/plugins/gnometerminal.py b/plugins/gnometerminal.py new file mode 100644 index 0000000..d97a320 --- /dev/null +++ b/plugins/gnometerminal.py @@ -0,0 +1,126 @@ +# -*- coding: UTF-8 -*- +# -*- python -*- +# Copyright (C) 2005 by Sebastien Estienne +# +# This file may be distributed and/or modified under the terms of +# the GNU General Public License version 2 as published by +# the Free Software Foundation. +# This file is distributed without any warranty; without even the implied +# warranty of merchantability or fitness for a particular purpose. +# See "COPYING" in the source distribution for more information. +# +# $id$ +# + +from sdapplet.pluginutils import * + +try: + import gettext + gettext.bindtextdomain("service-discovery-applet", "/usr/share/locale") + gettext.textdomain("service-discovery-applet") + _ = gettext.gettext + import pygtk + pygtk.require('2.0') + import gtk + import os + import pwd + import subprocess + import gnome +except ImportError, e: + error_msg(_("A required python module is missing!\n%s") % (e)) + sys.exit() + +class plugin_gnometerminal: + def __init__(self): + self.service_type = ["_ssh._tcp", "_sftp-ssh._tcp" ] + self.author = "Sébastien Estienne" + + def enter_callback(self, widget, win): + win.response(gtk.RESPONSE_OK) + + def SshLogin(self, hostname, username = None): + self.win = gtk.Dialog(_("SSH Connection"), None, + gtk.DIALOG_MODAL, + (gtk.STOCK_OK, gtk.RESPONSE_OK, + gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) + + vbox = gtk.VBox(False, 5) + self.win.vbox.pack_start(vbox, True, True, 0) + vbox.set_border_width(5) + + label = gtk.Label() + label.set_markup(_("Connecting to %s.\nPlease enter your login:") % (hostname)) + + vbox.pack_start(label, False, False, 0) + + # Create our entry + entry = gtk.Entry() + if username!= None: + entry.set_text(username) + entry.connect("activate", self.enter_callback, self.win) + vbox.pack_start(entry, False, False, 0) + + # Create the completion object + completion = gtk.EntryCompletion() + + # Assign the completion to the entry + entry.set_completion(completion) + + # Create a tree model and use it as the completion model + completion_model = self.__create_completion_model() + completion.set_model(completion_model) + + # Use model column 0 as the text column + completion.set_text_column(0) + + self.win.show_all() + if self.win.run() == gtk.RESPONSE_OK: + self.win.destroy() + return entry.get_text() + else: + self.win.destroy() + return None + + def __create_completion_model(self): + ''' Creates a tree model containing the completions. + ''' + store = gtk.ListStore(str) + + iter = store.append() + store.set(iter, 0, "root") + + current_user = pwd.getpwuid(os.getuid())[0] + iter = store.append() + store.set(iter, 0, current_user) + + return store + + def connect(self, name, stype, hostname, address, port, txts): + print "connecting using gnometerminal" + if txts.has_key("u"): + username = self.SshLogin(name, txts["u"]) + else: + username = self.SshLogin(name) + + + if stype == "_ssh._tcp": + scheme = "ssh" + else: + scheme = "sftp" + if username == None: + return + elif username != "": + sshline = "%s -p %i %s@%s" % (scheme, port, username, address) + else: + sshline = "%s -p %i %s " % (scheme, port, address) + + cmdline = [] + cmdline.append("gnome-terminal") + cmdline.append("--tab") + cmdline.append("-t %s" % name) + cmdline.append("-e %s" % sshline) + print cmdline + pid = subprocess.Popen(cmdline).pid + +def load(): + return plugin_gnometerminal() diff --git a/plugins/nautilus.py b/plugins/nautilus.py new file mode 100644 index 0000000..e208a8c --- /dev/null +++ b/plugins/nautilus.py @@ -0,0 +1,48 @@ +# -*- coding: UTF-8 -*- +# -*- python -*- +# Copyright (C) 2005 by Sebastien Estienne +# +# This file may be distributed and/or modified under the terms of +# the GNU General Public License version 2 as published by +# the Free Software Foundation. +# This file is distributed without any warranty; without even the implied +# warranty of merchantability or fitness for a particular purpose. +# See "COPYING" in the source distribution for more information. +# +# $id$ +# + +from sdapplet.pluginutils import * + +import gnome + +class plugin_nautilus: + def __init__(self): + self.service_type = ["_http._tcp", "_ftp._tcp" , "_https._tcp", "_ftps._tcp" , "_webdav._tcp", "_webdav._tcp", "_sftp-ssh._tcp"] + self.author = "Sébastien Estienne" + self.description = "Accessing zeroconf services using Nautilus" + + def connect(self, name, stype, hostname, address, port, txts): + print "connecting using nautilus" + path = get_txt_value(txts,"path") + username = get_txt_value(txts,"u") + password = get_txt_value(txts,"p") + if stype == "_http._tcp": + url = build_url("http",address,port, path, username,password) + if stype == "_https._tcp": + url = build_url("https",address,port, path, username,password) + if stype == "_ftp._tcp": + url = build_url("ftp",address,port, path, username,password) + if stype == "_ftps._tcp": + url = build_url("ftps",address,port, path, username,password) + if stype == "_sftp-ssh._tcp": + url = build_url("sftp",address,port, path, username,password) + if stype == "_webdav._tcp": + url = build_url("webdav",address,port, path, username,password) + if stype == "_webdavs._tcp": + url = build_url("webdavs",address,port, path, username,password) + gnome.url_show(url) + + +def load(): + return plugin_nautilus() diff --git a/po/POTFILES.in b/po/POTFILES.in index 1565f6b..b71f664 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -2,10 +2,10 @@ # List of source files containing translatable strings. # Please keep this file sorted alphabetically. -actions/services/__init__.py.in +plugins/gnometerminal.py +plugins/nautilus.py schemas/service-discovery-applet.schemas.in servers/GNOME_ServiceDiscoveryApplet.server.in src/service-discovery-applet.in src/service-discovery-config.glade src/service-discovery-config.in - diff --git a/src/Makefile.am b/src/Makefile.am index 88a8a6b..b96f551 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS = modules + interfacesdir = $(INTERFACESDIR) interfaces_DATA = service-discovery-config.glade @@ -18,7 +20,7 @@ service-discovery-applet: service-discovery-applet.in -e 's,@PYTHON\@,$(PYTHON),g' \ -e 's,@version\@,$(VERSION),g' \ -e 's,@iconsdir\@,$(ICONSDIR),g' \ - -e 's,@actionsdir\@,$(ACTIONSDIR),g' \ + -e 's,@pluginsdir\@,$(PLUGINSDIR),g' \ -e 's,@GETTEXT_PACKAGE\@,$(GETTEXT_PACKAGE),g' \ -e 's,@LOCALEDIR\@,$(LOCALEDIR),g' \ $< > $@ diff --git a/src/modules/Makefile.am b/src/modules/Makefile.am new file mode 100644 index 0000000..d0c50d6 --- /dev/null +++ b/src/modules/Makefile.am @@ -0,0 +1,24 @@ +sdadir = $(pythondir)/sdapplet + +pythonscripts = \ + pluginloader.py + +EXTRA_DIST = \ + __init__.py \ + pluginloader.py.in \ + pluginutils.py + +sda_PYTHON = $(pythonscripts) pluginutils.py __init__.py + +pluginloader.py: pluginloader.py.in + sed \ + -e 's,@PYTHON\@,$(PYTHON),g' \ + -e 's,@version\@,$(VERSION),g' \ + -e 's,@iconsdir\@,$(ICONSDIR),g' \ + -e 's,@actionsdir\@,$(ACTIONSDIR),g' \ + -e 's,@GETTEXT_PACKAGE\@,$(GETTEXT_PACKAGE),g' \ + -e 's,@LOCALEDIR\@,$(LOCALEDIR),g' \ + $< > $@ + chmod +x $@ + +CLEANFILES = $(pythonscripts) *.pyc *.pyo diff --git a/src/modules/__init__.py b/src/modules/__init__.py new file mode 100644 index 0000000..6cbfc04 --- /dev/null +++ b/src/modules/__init__.py @@ -0,0 +1,12 @@ +# -*- coding: UTF-8 -*- +# -*- python -*- +# Copyright (C) 2005 by Sebastien Estienne +# +# This file may be distributed and/or modified under the terms of +# the GNU General Public License version 2 as published by +# the Free Software Foundation. +# This file is distributed without any warranty; without even the implied +# warranty of merchantability or fitness for a particular purpose. +# See "COPYING" in the source distribution for more information. +# +# $id$ diff --git a/src/modules/pluginloader.py.in b/src/modules/pluginloader.py.in new file mode 100644 index 0000000..82357e8 --- /dev/null +++ b/src/modules/pluginloader.py.in @@ -0,0 +1,46 @@ +#!@PYTHON@ +# -*- coding: UTF-8 -*- +# -*- python -*- +# Copyright (C) 2005 by Sebastien Estienne +# +# This file may be distributed and/or modified under the terms of +# the GNU General Public License version 2 as published by +# the Free Software Foundation. +# This file is distributed without any warranty; without even the implied +# warranty of merchantability or fitness for a particular purpose. +# See "COPYING" in the source distribution for more information. +# +# $id$ + +import sys +import os + +class PluginLoader: + def __init__(self, path): + self.plugins = {} + print "Looking for plugin in %s." % (path) + sys.path.append(path) + plugin_dir = os.listdir(path) + for plugin in plugin_dir: + plugin_file = plugin.split('.',1) + if plugin_file[1] == "py": + print "New plugin found: %s" % plugin_file[0] + module = __import__(plugin_file[0]) + module_loaded = module.load() + for st in module_loaded.service_type: + if self.plugins.has_key(st) == False: + self.plugins[st] = [] + self.plugins[st].append(module_loaded) + + def dump_service_type(self): + print self.plugins + +def main(): + plugin_path = "/home/sebest/pluginloader/plugins" + plugin = PluginLoader(plugin_path) + plugin.dump_service_type() + plugin.plugins["_ssh._tcp"][0].connect("test", "_ssh._tcp", "coucou", "172.16.200.103", 22, {}) +# plugin.plugins["_sftp-ssh._tcp"][1].connect() + +if __name__ == "__main__": + main() diff --git a/src/modules/pluginutils.py b/src/modules/pluginutils.py new file mode 100644 index 0000000..61f1a3d --- /dev/null +++ b/src/modules/pluginutils.py @@ -0,0 +1,49 @@ +# -*- coding: UTF-8 -*- +# -*- python -*- +# Copyright (C) 2005 by Sebastien Estienne +# +# This file may be distributed and/or modified under the terms of +# the GNU General Public License version 2 as published by +# the Free Software Foundation. +# This file is distributed without any warranty; without even the implied +# warranty of merchantability or fitness for a particular purpose. +# See "COPYING" in the source distribution for more information. +# +# $id$ +# + +def pair_to_dict(l): + res = dict() + for el in l: + if "=" not in el: + res[el]='' + else: + tmp = el.split('=',1) + if len(tmp[0]) > 0: + res[tmp[0]] = tmp[1] + return res + + +def build_url(uri = "http", hostname="127.0.0.1", port = None, path = None, username = None, password = None): + if path and path != None: + if path[0] == "/": + path = path[1:] + else: + path = "" + + if username: + if password: + username="%s:%s@" % (username,password) + else: + username="%s@" % (username) + else: + username="" + if port and port != None: + hostname="%s:%i" % (hostname,port) + return "%s://%s%s/%s" % (uri,username,hostname,path) + +def get_txt_value(txts, txt): + if txts.has_key(txt): + return txts[txt] + else: + return None diff --git a/src/service-discovery-applet.in b/src/service-discovery-applet.in index 3949cec..6c23930 100755 --- a/src/service-discovery-applet.in +++ b/src/service-discovery-applet.in @@ -20,8 +20,8 @@ import subprocess import sys import pygtk -sys.path.append("@actionsdir@") -import services +import sdapplet.pluginloader +import sdapplet.pluginutils pygtk.require('2.0') @@ -207,6 +207,9 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): self.zc_types = {} self.zc_services = {} + # Plugins + self.plugin = sdapplet.pluginloader.PluginLoader("@pluginsdir@") + self.sdaGconf = SDAGconf(self) self.show_local_services = self.sdaGconf.get_option("show_local_services") self.show_notifications = self.sdaGconf.get_option("show_notifications") @@ -282,8 +285,8 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, avahi.txt_array_to_string_array(txt)) txts = avahi.txt_array_to_string_array(txt) - txts = services.pair_to_dict(txts) - services.handle(name, type, host, address, port, txts) + txts = sdapplet.pluginutils.pair_to_dict(txts) + self.plugin.plugins[type][0].connect(name, type, host, address, port, txts) def print_error(self, err): # FIXME we should use notifications @@ -307,7 +310,6 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): if self.server.IsServiceLocal( interface, protocol, name, type, domain) == True: return else: -# FIXME not yet available in python avahi try: if flags & avahi.LOOKUP_RESULT_LOCAL: return -- cgit