""" 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()