Merged my unitary FFT wrappers (FFT_tools) as hooke.util.fft.
[hooke.git] / hooke / plugin / debug.py
1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
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.
9 #
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.
14 #
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/>.
18
19 """The `debug` module provides :class:`DebugPlugin` and associated
20 :class:`hooke.command.Command`\s which provide useful debugging
21 information.
22 """
23
24 import platform
25 import sys
26
27 from .. import version
28 from ..command import Command, Argument
29 from ..plugin import Builtin
30
31
32 class DebugPlugin (Builtin):
33     def __init__(self):
34         super(DebugPlugin, self).__init__(name='debug')
35
36     def commands(self):
37         return [VersionCommand(), DebugCommand()]
38
39
40 class VersionCommand (Command):
41     """Get the Hooke version, as well as versions for important Python
42     packages.  Useful for debugging.
43     """
44     def __init__(self):
45         super(VersionCommand, self).__init__(
46             name='version', help=self.__doc__)
47
48     def _run(self, hooke, inqueue, outqueue, params):
49         lines = [
50             'Hooke ' + version(),
51             '----',
52             'Python ' + sys.version]
53         for name,module in sorted(sys.modules.items()):
54             if name == 'hooke':
55                 continue
56             v = getattr(module, '__version__', None)
57             if v != None:
58                 lines.append('%s %s' % (name, v))
59         lines.extend([
60                 '----',
61                 'Platform: %s' % ' '.join(platform.uname()),
62                 'User interface: %s' % hooke.ui.name,
63                 '----',
64                 'Loaded plugins:'])
65         lines.extend([p.name for p in hooke.plugins])
66         lines.extend([
67                 '----',
68                 'Loaded drivers:'])
69         lines.extend([d.name for d in hooke.drivers])
70         outqueue.put('\n'.join(lines))
71
72
73 class DebugCommand (Command):
74     """Get Hooke attributes.  Useful for debugging.
75     """
76     def __init__(self):
77         super(DebugCommand, self).__init__(
78             name='debug',
79             arguments=[
80                 Argument(name='attribute', help="""
81 Hooke attribute to print.
82 """.strip()),
83                 ],
84             help=self.__doc__)
85
86     def _run(self, hooke, inqueue, outqueue, params):
87         if params['attribute'] == None:
88             outqueue.put(hooke)
89         else:
90             outqueue.put(getattr(hooke, params['attribute']))