1 # Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option) any
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with Hooke. If not, see <http://www.gnu.org/licenses/>.
18 """The `debug` module provides :class:`DebugPlugin` and associated
19 :class:`hooke.command.Command`\s which provide useful debugging
26 from .. import version
27 from ..command import Command, Argument
31 class DebugPlugin (Builtin):
33 super(DebugPlugin, self).__init__(name='debug')
34 self._commands = [VersionCommand(self), DebugCommand(self)]
37 class VersionCommand (Command):
38 """Get the Hooke version, as well as versions for important Python
39 packages. Useful for debugging.
41 def __init__(self, plugin):
42 super(VersionCommand, self).__init__(
43 name='version', help=self.__doc__, plugin=plugin)
45 def _run(self, hooke, inqueue, outqueue, params):
49 'Python ' + sys.version]
50 for name,module in sorted(sys.modules.items()):
53 v = getattr(module, '__version__', None)
55 lines.append('%s %s' % (name, v))
58 'Platform: %s' % ' '.join(platform.uname()),
59 'User interface: %s' % hooke.ui.name,
62 lines.extend([p.name for p in hooke.plugins])
66 lines.extend([d.name for d in hooke.drivers])
67 outqueue.put('\n'.join(lines))
70 class DebugCommand (Command):
71 """Get Hooke attributes. Useful for debugging.
73 def __init__(self, plugin):
74 super(DebugCommand, self).__init__(
77 Argument(name='attribute', help="""
78 Hooke attribute to print.
81 help=self.__doc__, plugin=plugin)
83 def _run(self, hooke, inqueue, outqueue, params):
84 if params['attribute'] == None:
87 outqueue.put(getattr(hooke, params['attribute']))