Autocomplete working in query_editor plugin
[unfold.git] / manifold / util / plugin_factory.py
diff --git a/manifold/util/plugin_factory.py b/manifold/util/plugin_factory.py
new file mode 100644 (file)
index 0000000..1956355
--- /dev/null
@@ -0,0 +1,24 @@
+from manifold.util.log             import Log
+
+class PluginFactory(type):
+    def __init__(cls, name, bases, dic):
+        #super(PluginFactory, cls).__init__(name, bases, dic)
+        type.__init__(cls, name, bases, dic)
+
+        try:
+            registry = getattr(cls, 'registry')
+        except AttributeError:
+            setattr(cls, 'registry', {})
+            registry = getattr(cls, 'registry')
+        # XXX
+        if name != "Gateway":
+            if name.endswith('Gateway'):
+                name = name[:-7]
+            name = name.lower()
+            registry[name] = cls
+
+        def get(self, name):
+            return registry[name.lower()]
+
+        # Adding a class method get to retrieve plugins by name
+        setattr(cls, 'get', classmethod(get))