summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSebastien Estienne <sebastien.estienne@gmail.com>2005-11-19 00:33:52 +0000
committerSebastien Estienne <sebastien.estienne@gmail.com>2005-11-19 00:33:52 +0000
commit5ce17adcb1ff31ffdc2618fcf4788beecc1e1ff8 (patch)
tree0039768e4f21777c78e1f893c51d5253ed72153a /src
parentd8bc0dbb720eefc1d7189c99ae8045524952eb46 (diff)
* 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
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/modules/Makefile.am24
-rw-r--r--src/modules/__init__.py12
-rw-r--r--src/modules/pluginloader.py.in46
-rw-r--r--src/modules/pluginutils.py49
-rwxr-xr-xsrc/service-discovery-applet.in12
6 files changed, 141 insertions, 6 deletions
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