trepan/processor/command/base_submgr.py
def _load_debugger_subcommands(self, name):
        """ Create an instance of each of the debugger
        subcommands. Commands are found by importing files in the
        directory 'name' + 'sub'. Some files are excluded via an array set
        in __init__.  For each of the remaining files, we import them
        and scan for class names inside those files and for each class
        name, we will create an instance of that class. The set of
        DebuggerCommand class instances form set of possible debugger
        commands."""

        # Initialization
        cmd_instances     = []
        class_prefix      = capitalize(name)  # e.g. Info, Set, or Show
        module_dir        = 'trepan.processor.command.%s_subcmd' % name
        mod               = __import__(module_dir, None, None, ['*'])
        eval_cmd_template = 'command_mod.%s(self)'

        # Import, instantiate, and add classes for each of the
        # modules found in module_dir imported above.
        for module_name in mod.__modules__:
            import_name = module_dir + '.' + module_name
            try:
                command_mod = importlib.import_module(import_name)
            except ImportError:
                print(("Error importing name %s module %s: %s" %
                      (import_name, module_name, sys.exc_info()[0])))
                continue

            # Even though we tend not to do this, it is possible to
            # put more than one class into a module/file.  So look for
            # all of them.
            classnames = [ classname for classname, classvalue in
                           inspect.getmembers(command_mod, inspect.isclass)
                           if ('DebuggerCommand' != classname and
                               classname.startswith(class_prefix)) ]

            for classname in classnames:
                eval_cmd = eval_cmd_template % classname
                try:
                    instance = eval(eval_cmd)
                    self.cmds.add(instance)
                except:
                    print("Error eval'ing class %s" % classname)
                    pass
                pass
            pass
        return cmd_instances
def _load_debugger_subcommands(self, name):
        """ Create an instance of each of the debugger
        subcommands. Commands are found by importing files in the
        directory 'name' + 'sub'. Some files are excluded via an array set
        in __init__.  For each of the remaining files, we import them
        and scan for class names inside those files and for each class
        name, we will create an instance of that class. The set of
        DebuggerCommand class instances form set of possible debugger
        commands."""

        # Initialization
        cmd_instances     = []
        class_prefix      = capitalize(name)  # e.g. Info, Set, or Show
        module_dir        = 'trepan.processor.command.%s_subcmd' % name
        mod               = __import__(module_dir, None, None, ['*'])
        eval_cmd_template = 'command_mod.%s(self)'

        # Import, instantiate, and add classes for each of the
        # modules found in module_dir imported above.
        for module_name in mod.__modules__:
            import_name = module_dir + '.' + module_name
            try:
                command_mod = importlib.import_module(import_name)
            except ImportError:
                print(("Error importing name %s module %s: %s" %
                      (import_name, module_name, sys.exc_info()[0])))
                continue

            # Even though we tend not to do this, it is possible to
            # put more than one class into a module/file.  So look for
            # all of them.
            classnames = [ classname for classname, classvalue in
                           inspect.getmembers(command_mod, inspect.isclass)
                           if ('DebuggerCommand' != classname and
                               classname.startswith(class_prefix)) ]

            for classname in classnames:
                eval_cmd = eval_cmd_template % classname
                try:
                    instance = eval(eval_cmd)
                    self.cmds.add(instance)
                except:
                    print("Error eval'ing class %s" % classname)
                    pass
                pass
            pass
        return cmd_instances
Create an instance of each of the debugger
        subcommands. Commands are found by importing files in the
        directory 'name' + 'sub'. Some files are excluded via an array set
        in __init__.  For each of the remaining files, we import them
        and scan for class names inside those files and for each class
        name, we will create an instance of that class. The set of
        DebuggerCommand class instances form set of possible debugger
        commands.