[conduit: 110/138] Missing file
- From: John Carr <johncarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [conduit: 110/138] Missing file
- Date: Thu, 21 May 2009 03:36:09 -0400 (EDT)
commit 4070e31ba7b1bfb106bd293cc0e35059ffbf75cf
Author: John Carr <john carr unrouted co uk>
Date: Wed May 6 02:59:40 2009 -0700
Missing file
---
test/soup/utils/pluginloader.py | 34 ++++++++++++++++++++++++++++++++++
1 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/test/soup/utils/pluginloader.py b/test/soup/utils/pluginloader.py
new file mode 100644
index 0000000..85a914d
--- /dev/null
+++ b/test/soup/utils/pluginloader.py
@@ -0,0 +1,34 @@
+
+import sys
+import os
+
+class PluginLoader(object):
+ """ Walks a directory and loads all modules within, providing access to anything that
+ implements self._subclass_ """
+
+ _subclass_ = None
+ _module_ = None
+ _path_ = None
+
+ def load_modules(self):
+ for root, dirs, files in os.walk(self._path_):
+ for dir in dirs:
+ if dir[:1] != ".":
+ self.load_module(dir)
+ for file in files:
+ if file.endswith(".py") and not file.startswith("__"):
+ self.load_module(file[:-3])
+ break
+
+ def load_module(self, module):
+ if sys.modules.has_key(module):
+ reload(sys.modules[module])
+ else:
+ __import__(self._module_, {}, {}, [module])
+
+ def get_all(self):
+ if len(self._subclass_.__subclasses__()) == 0:
+ self.load_modules()
+ return self._subclass_.__subclasses__()
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]