Rework Plugin.commands() to include _setup_commands().
[hooke.git] / hooke / plugin / __init__.py
index 89a23b248e750b0bf8220dd2296a9c7e622d7fe1..2418b69d5d3903c95b10ea781265f8678388d51a 100644 (file)
@@ -34,7 +34,7 @@ PLUGIN_MODULES = [
     ('cut', True),
 #    ('fit', True),
 #    ('flatfilts-rolf', True),
-#    ('flatfilts', True),
+    ('flatfilt', True),
 #    ('generalclamp', True),
 #    ('generaltccd', True),
 #    ('generalvclamp', True),
@@ -83,9 +83,10 @@ class Plugin (object):
         self.name = name
         self.setting_section = '%s plugin' % self.name
         self.config = {}
+        self._commands = []
 
     def dependencies(self):
-        """Return a list of :class:`Plugin`\s we require."""
+        """Return a list of names of :class:`Plugin`\s we require."""
         return []
 
     def default_settings(self):
@@ -98,10 +99,21 @@ class Plugin (object):
         """
         return []
 
+    def _setup_commands(self):
+        """Perform internal setup on stored commands.
+
+        Currently:
+
+        * Adds a `plugin` attribute to each command so they can access
+          the plugin configuration with `.plugin.config`.
+        """
+        for command in self._commands:
+            command.plugin = self
+
     def commands(self):
         """Return a list of :class:`hooke.command.Command`\s provided.
         """
-        return []
+        return list(self._commands)
 
 class Builtin (Plugin):
     """A required collection of Hooke commands.