Rework Plugin.commands() to include _setup_commands().
authorW. Trevor King <wking@drexel.edu>
Tue, 18 May 2010 11:34:02 +0000 (07:34 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 18 May 2010 11:34:02 +0000 (07:34 -0400)
The previous implementation gave Commands no way to access the
Plugin's configuration.

hooke/plugin/__init__.py
hooke/plugin/config.py
hooke/plugin/curve.py
hooke/plugin/cut.py
hooke/plugin/debug.py
hooke/plugin/multifit.py
hooke/plugin/note.py
hooke/plugin/playlist.py
hooke/plugin/system.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.
index ff76d8f66321215742b157da1b91811a22c4778d..7cb4ef5af8caf816621e09324ef2c6b6b3da4ac7 100644 (file)
@@ -31,9 +31,8 @@ from ..plugin import Builtin
 class ConfigPlugin (Builtin):
     def __init__(self):
         super(ConfigPlugin, self).__init__(name='config')
-
-    def commands(self):
-        return [GetCommand(), SetCommand(), PrintCommand()]
+        self._commands = [GetCommand(), SetCommand(), PrintCommand()]
+        self._setup_commands()
 
 
 # Define common or complicated arguments
index af427d6734ddcc65411eed43089728533b0ed4c1..27fb0cd9fbdc4b7a862ffc5856e1416e7f9ba9eb 100644 (file)
@@ -35,11 +35,11 @@ from ..util.fft import unitary_avg_power_spectrum
 class CurvePlugin (Builtin):
     def __init__(self):
         super(CurvePlugin, self).__init__(name='curve')
-
-    def commands(self):
-        return [InfoCommand(), ExportCommand(),
-                DifferenceCommand(), DerivativeCommand(),
-                PowerSpectrumCommand()]
+        self._commands = [
+            InfoCommand(), ExportCommand(),
+            DifferenceCommand(), DerivativeCommand(),
+            PowerSpectrumCommand()]
+        self._setup_commands()
 
 
 # Define common or complicated arguments
index f3c13c9914c0f4e2b407111149ae7dba02acfcc0..7a2e5ead3e3c24e08113b1d9bd3c1adda15ee8bc 100644 (file)
@@ -29,9 +29,8 @@ from ..plugin import Plugin
 class CutPlugin (Plugin):
     def __init__(self):
         super(CutPlugin, self).__init__(name='cut')
-
-    def commands(self):
-        return [CutCommand()]
+        self._commands = [CutCommand()]
+        self._setup_commands()
 
 
 # Define common or complicated arguments
index a786af07d1190b3b765ce23d4648af82961fb3a5..cc9101de77081d1978860c9ef56e444675106095 100644 (file)
@@ -32,9 +32,8 @@ from ..plugin import Builtin
 class DebugPlugin (Builtin):
     def __init__(self):
         super(DebugPlugin, self).__init__(name='debug')
-
-    def commands(self):
-        return [VersionCommand(), DebugCommand()]
+        self._commands = [VersionCommand(), DebugCommand()]
+        self._setup_commands()
 
 
 class VersionCommand (Command):
index 986b7813a26e23de57cef0baec2004ded9f39647..ee42ea56f3eb9d39148988e41bc5e5d2baaf485f 100644 (file)
@@ -31,9 +31,9 @@ from ..plugin.playlist import PlaylistArgument
 class MultifitPlugin (Plugin):
     def __init__(self):
         super(MultifitPlugin, self).__init__(name='multifit')
+        self._commands = [MultifitCommand()]
+        self._setup_commands()
 
-    def commands(self):
-        return [MultifitCommand()]
 
 class MultifitCommand (Command):
     """Presents curves for interactive manual analysis.
index 168cbd34f050cbd01e6176b1faa666a15e6a6022..722b20812b22015d174ec6026025d9f9e555968a 100644 (file)
@@ -30,14 +30,9 @@ from ..plugin.playlist import current_playlist_callback
 class NotePlugin (Builtin):
     def __init__(self):
         super(NotePlugin, self).__init__(name='note')
-
-    def commands(self):
-        return [AddNoteCommand(), ClearNoteCommand(), GetNoteCommand()]
-
-    def dependencies(self):
-        return [
-            'playlist', # for current_playlist_callback
-            ]
+        self._commands = [
+            AddNoteCommand(), ClearNoteCommand(), GetNoteCommand()]
+        self._setup_commands()
 
 
 class AddNoteCommand (Command):
index 371cd1e4573bad145535dae54ef1449193764b28..47975f4a468b5409f065f0e66cc60cb0ae6ee4f7 100644 (file)
@@ -31,13 +31,13 @@ from ..plugin import Builtin
 class PlaylistPlugin (Builtin):
     def __init__(self):
         super(PlaylistPlugin, self).__init__(name='playlist')
-
-    def commands(self):
-        return [NextCommand(), PreviousCommand(), JumpCommand(),
-                IndexCommand(), CurveListCommand(),
-                SaveCommand(), LoadCommand(),
-                AddCommand(), AddGlobCommand(),
-                RemoveCommand(), FilterCommand(), NoteFilterCommand()]
+        self._commands = [
+            NextCommand(), PreviousCommand(), JumpCommand(),
+            IndexCommand(), CurveListCommand(),
+            SaveCommand(), LoadCommand(),
+            AddCommand(), AddGlobCommand(),
+            RemoveCommand(), FilterCommand(), NoteFilterCommand()]
+        self._setup_commands()
 
 
 # Define common or complicated arguments
index 42e9cbe3a11bd0db7e382f032aab99930eee9b5c..185fa8e44cd312b5bbbedf6e00e82b165af253ca 100644 (file)
@@ -33,10 +33,10 @@ from ..plugin import Builtin
 class SystemPlugin (Builtin):
     def __init__(self):
         super(SystemPlugin, self).__init__(name='system')
-
-    def commands(self):
-        return [ListDirectoryCommand(), GetWorkingDirectoryCommand(),
-                ChangeDirectoryCommand(), SystemCommand()]
+        self._commands = [
+            ListDirectoryCommand(), GetWorkingDirectoryCommand(),
+            ChangeDirectoryCommand(), SystemCommand()]
+        self._setup_commands()
 
 
 class ListDirectoryCommand (Command):