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