summaryrefslogtreecommitdiffstats
path: root/src/modules
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/modules
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/modules')
-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
4 files changed, 131 insertions, 0 deletions
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