summaryrefslogtreecommitdiff
path: root/gr-utils/src/python/modtool/modtool_help.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-utils/src/python/modtool/modtool_help.py')
-rw-r--r--gr-utils/src/python/modtool/modtool_help.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/gr-utils/src/python/modtool/modtool_help.py b/gr-utils/src/python/modtool/modtool_help.py
new file mode 100644
index 000000000..a1dd3c466
--- /dev/null
+++ b/gr-utils/src/python/modtool/modtool_help.py
@@ -0,0 +1,66 @@
+""" The help module """
+
+from modtool_base import ModTool
+from modtool_info import ModToolInfo
+from modtool_add import ModToolAdd
+from modtool_rm import ModToolRemove
+from modtool_newmod import ModToolNewModule
+from modtool_disable import ModToolDisable
+from modtool_makexml import ModToolMakeXML
+from util_functions import get_command_from_argv
+from templates import Templates
+
+def get_class_dict():
+ " Return a dictionary of the available commands in the form command->class "
+ classdict = {}
+ for g in globals().values():
+ try:
+ if issubclass(g, ModTool):
+ classdict[g.name] = g
+ for a in g.aliases:
+ classdict[a] = g
+ except (TypeError, AttributeError):
+ pass
+ return classdict
+
+
+### Help module ##############################################################
+def print_class_descriptions():
+ ''' Go through all ModTool* classes and print their name,
+ alias and description. '''
+ desclist = []
+ for gvar in globals().values():
+ try:
+ if issubclass(gvar, ModTool) and not issubclass(gvar, ModToolHelp):
+ desclist.append((gvar.name, ','.join(gvar.aliases), gvar.__doc__))
+ except (TypeError, AttributeError):
+ pass
+ print 'Name Aliases Description'
+ print '====================================================================='
+ for description in desclist:
+ print '%-8s %-12s %s' % description
+
+class ModToolHelp(ModTool):
+ ''' Show some help. '''
+ name = 'help'
+ aliases = ('h', '?')
+ def __init__(self):
+ ModTool.__init__(self)
+
+ def setup(self):
+ pass
+
+ def run(self):
+ cmd_dict = get_class_dict()
+ cmds = cmd_dict.keys()
+ cmds.remove(self.name)
+ for a in self.aliases:
+ cmds.remove(a)
+ help_requested_for = get_command_from_argv(cmds)
+ if help_requested_for is None:
+ print 'Usage:' + Templates['usage']
+ print '\nList of possible commands:\n'
+ print_class_descriptions()
+ return
+ cmd_dict[help_requested_for]().setup_parser().print_help()
+