From 0b5ebe2e1b3becfd57c15dc3d585ffcd22b47076 Mon Sep 17 00:00:00 2001 From: Bogdano Arendartchuk Date: Wed, 2 May 2007 17:39:28 +0000 Subject: Merged work on plugins support, including the possibility to wrap configuration sections. --- RepSys/plugins/__init__.py | 27 +++++++++++++++++++++++++++ RepSys/plugins/sample.py.txt | 14 ++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 RepSys/plugins/__init__.py create mode 100644 RepSys/plugins/sample.py.txt (limited to 'RepSys/plugins') diff --git a/RepSys/plugins/__init__.py b/RepSys/plugins/__init__.py new file mode 100644 index 0000000..8bf4521 --- /dev/null +++ b/RepSys/plugins/__init__.py @@ -0,0 +1,27 @@ +import os + +loaded = {} + +def load(): + # based on smart's plugin system + pluginsdir = os.path.dirname(__file__) + for entry in os.listdir(pluginsdir): + if entry != "__init__.py" and entry.endswith(".py"): + name = entry[:-3] + loaded[name] = __import__("RepSys.plugins."+name, + fromlist=[name]) + elif os.path.isdir(entry): + initfile = os.path.join(entry, "__init__.py") + if os.path.isfile(initfile): + loaded[entry] = __import__("RepSys.plugins."+entry, + fromlist=[entry]) + +def list(): + return loaded.keys() + +def help(name): + from RepSys import Error + try: + return loaded[name].__doc__ + except KeyError: + raise Error, "plugin %s not found" % name diff --git a/RepSys/plugins/sample.py.txt b/RepSys/plugins/sample.py.txt new file mode 100644 index 0000000..9877f3c --- /dev/null +++ b/RepSys/plugins/sample.py.txt @@ -0,0 +1,14 @@ +# Sample repsys plugin. In order to test it, rename to sample.py +# vim:ft=python +from RepSys import config + +def users_wrapper(section, option=None, default=None, walk=False): + d = {"foolano": "Foolano De Tal ", + "ceeclano": "Ceeclano Algumacoisa ", + "beltrano": "Beltrano Bla "} + if walk: + return d.items() + + return d.get(option, default) + +config.wrap("users", handler=users_wrapper) -- cgit v1.2.1