コード例 #1
0
ファイル: cli.py プロジェクト: mydaisy2/targetcli
 def onecmd(self, line):
     '''
     Executes a command line.
     '''
     try:
         result = cmd.Cmd.onecmd(self, line)
     except pp.ParseException, e:
         log.error("Unknown syntax: %s at char %d" % (e.msg, e.loc))
         return None
コード例 #2
0
ファイル: cli.py プロジェクト: mydaisy2/targetcli
    def do_trace(self, options):
        '''
        trace

        Displays the last exception trace for the current mode.

        This is useful only for debugging the application. Your lio support
        team might ask you to run this command to help understanding an issue
        you're experimenting.
        '''
        options = self.parse(options, 'trace', '')[1:]
        if self.last_traceback is not None:
            log.error(self.last_traceback)
        else:
            log.error("No previous exception traceback.")
コード例 #3
0
ファイル: cli_live.py プロジェクト: wedged/targetcli
    def do_show(self, options):
        '''
        show [all] [PATH]

        Shows the running live configuration for PATH.

        Note that attributes with default values will be
        filrered out by default, unless the all option is used.
        '''
        if options and options.split()[0] == 'all':
            options = " ".join(options.split()[1:])
            node_filter = lambda x:x
        else:
            node_filter = filter_no_default

        config = self.config.dump(options, node_filter)
        if config is None:
            config = self.config.dump("%s .*" % options, node_filter)
        if config is not None:
            sys.stdout.write("%s\n" % config)
        else:
            log.error("No such path in current configuration: %s" % options)
コード例 #4
0
ファイル: cli_config.py プロジェクト: kissthink/targetcli
    def do_show(self, options):
        '''
        show [all] [PATH]

        Shows the current candidate configuration for PATH, relative to the
        current edit level. 

        Note that attributes with default values will be
        filrered out by default, unless the all option is used.
        '''
        if options and options.split()[0] == 'all':
            options = " ".join(options.split()[1:])
            node_filter = lambda x:x
        else:
            node_filter = filter_no_default

        path = ("%s %s" % (self.edit_levels[-1], options)).strip()
        config = self.config.dump(path, node_filter)
        if config is None:
            config = self.config.dump("%s .*" % path, node_filter)
        if config is not None:
            sys.stdout.write("%s\n" % config)
        else:
            log.error("No such path in current configuration: %s" % path)
コード例 #5
0
    def do_show(self, options):
        '''
        show [all] [PATH]

        Shows the current candidate configuration for PATH, relative to the
        current edit level. 

        Note that attributes with default values will be
        filrered out by default, unless the all option is used.
        '''
        if options and options.split()[0] == 'all':
            options = " ".join(options.split()[1:])
            node_filter = lambda x: x
        else:
            node_filter = filter_no_default

        path = ("%s %s" % (self.edit_levels[-1], options)).strip()
        config = self.config.dump(path, node_filter)
        if config is None:
            config = self.config.dump("%s .*" % path, node_filter)
        if config is not None:
            sys.stdout.write("%s\n" % config)
        else:
            log.error("No such path in current configuration: %s" % path)
コード例 #6
0
ファイル: cli.py プロジェクト: mydaisy2/targetcli
                intro = ''
            else:
                break

    def onecmd(self, line):
        '''
        Executes a command line.
        '''
        try:
            result = cmd.Cmd.onecmd(self, line)
        except pp.ParseException, e:
            log.error("Unknown syntax: %s at char %d" % (e.msg, e.loc))
            return None
        except ConfigError, e:
            self.last_traceback = traceback.format_exc()
            log.error(str(e))
        except CliError, e:
            self.last_traceback = traceback.format_exc()
            log.error(str(e))
        except Exception, e:
            self.last_traceback = traceback.format_exc()
            log.error("%s: %s\n" % (e.__class__.__name__, e))
            return None
        else:
            self.save_history()
            return result

    def completenames(self, text, *ignored):
        return ["%s " % name[3:] for name in self.get_names()
                if name.startswith("do_%s" % text)
                if not name in ['do_EOF']]