From: W. Trevor King Date: Wed, 12 May 2010 12:33:25 +0000 (-0400) Subject: Moved debuging commands from hooke_cli and plugin.system to plugin.debug. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b9e0a996adb827dd875294e3392b234b7a5deaea;p=hooke.git Moved debuging commands from hooke_cli and plugin.system to plugin.debug. --- diff --git a/hooke/hooke_cli.py b/hooke/hooke_cli.py index 568aa48..b283353 100644 --- a/hooke/hooke_cli.py +++ b/hooke/hooke_cli.py @@ -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() diff --git a/hooke/plugin/__init__.py b/hooke/plugin/__init__.py index 6014a66..5c4ca51 100644 --- a/hooke/plugin/__init__.py +++ b/hooke/plugin/__init__.py @@ -14,6 +14,7 @@ PLUGIN_MODULES = [ # ('autopeak', True), # ('curvetools', True), ('cut', True), + ('debug', True), # ('fit', True), # ('flatfilts-rolf', True), # ('flatfilts', True), diff --git a/hooke/plugin/curvetools.py b/hooke/plugin/curvetools.py index 63513ba..088e48e 100755 --- a/hooke/plugin/curvetools.py +++ b/hooke/plugin/curvetools.py @@ -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 index 0000000..66b2028 --- /dev/null +++ b/hooke/plugin/debug.py @@ -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']))