Moved debuging commands from hooke_cli and plugin.system to plugin.debug.
authorW. Trevor King <wking@drexel.edu>
Wed, 12 May 2010 12:33:25 +0000 (08:33 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 12 May 2010 12:33:25 +0000 (08:33 -0400)
hooke/hooke_cli.py
hooke/plugin/__init__.py
hooke/plugin/curvetools.py
hooke/plugin/debug.py [new file with mode: 0644]

index 568aa4854f3293f6a036f311fae2bceebab0dbb8..b2833535f6819e5929778126247f93dc4c678e3d 100644 (file)
@@ -690,25 +690,6 @@ Syntax copylog [directory]
         else:
             self.outlet.delete(args)
 
-    def do_debug(self,args):
-        '''
-        this is a dummy command where I put debugging things
-        '''
-        print self.config['plotmanips']
-        pass
-
-    def help_current(self):
-        print '''
-CURRENT
-Prints the current curve path.
-------
-Syntax: current
-        '''
-    def do_current(self,args):
-        print self.current.path
-
-
-
 if __name__ == '__main__':
     mycli=HookeCli(0)
     mycli.cmdloop()
index 6014a66207666ff4eeabd0bccb9c302a0b3a4870..5c4ca51572945e3b948e0c7f5b85ea5835d6ad16 100644 (file)
@@ -14,6 +14,7 @@ PLUGIN_MODULES = [
 #    ('autopeak', True),
 #    ('curvetools', True),
     ('cut', True),
+    ('debug', True),
 #    ('fit', True),
 #    ('flatfilts-rolf', True),
 #    ('flatfilts', True),
index 63513ba4b640e4fc869cab183b090ed47c9712cf..088e48ef52a290252d7fc39161160c71f4c087d4 100755 (executable)
@@ -122,3 +122,14 @@ Command line to execute.
             for set in plot.vectors:
                 lengths=[len(item) for item in set]
                 print 'Data set size: ',lengths
+
+
+    def help_current(self):
+        print '''
+CURRENT
+Prints the current curve path.
+------
+Syntax: current
+        '''
+    def do_current(self,args):
+        print self.current.path
diff --git a/hooke/plugin/debug.py b/hooke/plugin/debug.py
new file mode 100644 (file)
index 0000000..66b2028
--- /dev/null
@@ -0,0 +1,72 @@
+"""The `debug` module provides :class:`DebugPlugin` and associated
+:class:`hooke.command.Command`\s which provide useful debugging
+information.
+"""
+
+import platform
+import sys
+
+from .. import version
+from ..command import Command, Argument
+from ..plugin import Builtin
+
+
+class DebugPlugin (Builtin):
+    def __init__(self):
+        super(DebugPlugin, self).__init__(name='debug')
+
+    def commands(self):
+        return [VersionCommand(), DebugCommand()]
+
+
+class VersionCommand (Command):
+    """Get the Hooke version, as well as versions for important Python
+    packages.  Useful for debugging.
+    """
+    def __init__(self):
+        super(VersionCommand, self).__init__(
+            name='version', help=self.__doc__)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+        lines = [
+            'Hooke ' + version(),
+            '---',
+            'Python ' + sys.version]
+        for name,module in sorted(sys.modules.items()):
+            if name == 'hooke':
+                continue
+            v = getattr(module, '__version__', None)
+            if v != None:
+                lines.append('%s %s' % (name, v))
+        lines.extend([
+                '---',
+                'Platform: %s' % ' '.join(platform.uname()),
+                'User interface: %s' % hooke.ui.name,
+                '---',
+                'Loaded plugins:'])
+        lines.extend([p.name for p in hooke.plugins])
+        lines.extend([
+                '---',
+                'Loaded drivers:'])
+        lines.extend([d.name for d in hooke.drivers])
+        outqueue.put('\n'.join(lines))
+
+
+class DebugCommand (Command):
+    """Get Hooke attributes.  Useful for debugging.
+    """
+    def __init__(self):
+        super(DebugCommand, self).__init__(
+            name='debug',
+            arguments=[
+                Argument(name='attribute', help="""
+Hooke attribute to print.
+""".strip()),
+                ],
+            help=self.__doc__)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+        if params['attribute'] == None:
+            outqueue.put(hooke)
+        else:
+            outqueue.put(getattr(hooke, params['attribute']))