def blue(self, text): self._restoreColor() if platform.system() == 'Windows': # pragma: no cover # Default blue in windows is unreadable (such awful defaults...) return termstyle.cyan(text) else: return termstyle.blue(text)
def __init__(self, cfg_yaml_path=None, silent_mode=False, virtual_mode=False): # super(InteractivePlatform, self).__init__() cmd.Cmd.__init__(self) self.virtual_mode = virtual_mode self.platform = CPlatform(silent_mode) if cfg_yaml_path is None: try: cfg_yaml_path = raw_input( termstyle.cyan( "Please enter a readable .yaml configuration file path: " )) cfg_yaml_path = os.path.abspath(cfg_yaml_path) except KeyboardInterrupt: exit(-1) try: self.device_cfg = CDeviceCfg(cfg_yaml_path) self.platform.load_platform_data_from_file(self.device_cfg) if not virtual_mode: # if not virtual mode, try to establish a phyisical connection to platform self.platform.launch_connection(self.device_cfg) except Exception as inst: print(termstyle.magenta(inst)) exit(-1)
def _fmt_message_sqlalchemy_line(self, line, match, color): logger = match.group(1) level = match.group(2) verb = match.group(3) rest = match.group(4) if len(match.groups()) > 3 else '' if verb in ['SELECT']: head = color("%s: %s:" % (logger, level)) self._in_multiline_sql = verb self._in_multiline_sql_color = termstyle.cyan return "%s %s %s" % (head, termstyle.bold(termstyle.cyan(verb)), termstyle.cyan(rest)) elif verb in ['BEGIN', 'SAVEPOINT', 'RELEASE', 'ROLLBACK', 'COMMIT']: head = color("%s: %s:" % (logger, level)) self._in_multiline_sql = verb self._in_multiline_sql_color = termstyle.green return "%s %s %s" % (head, termstyle.bold(termstyle.green(verb)), termstyle.green(rest)) elif verb in ['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE']: head = color("%s: %s:" % (logger, level)) self._in_multiline_sql = verb self._in_multiline_sql_color = termstyle.red return "%s %s %s" % (head, termstyle.bold(termstyle.red(verb)), termstyle.red(rest)) return color(line)
def _format_traceback_line(self, tb): """ Formats the file / lineno / function line of a traceback element. Returns None is the line is not relevent to the user i.e. inside the test runner. """ if self._is_relevant_tb_level(tb): return None f = tb.tb_frame filename = f.f_code.co_filename lineno = tb.tb_lineno linecache.checkcache(filename) function_name = f.f_code.co_name line_contents = linecache.getline(filename, lineno, f.f_globals).strip() return " %s line %s in %s\n %s" % ( termstyle.blue(self._relative_path(filename) if self.use_relative_path else filename), termstyle.bold(termstyle.cyan(lineno)), termstyle.cyan(function_name), line_contents )
def _file_line(self, tb): """formats the file / lineno / function line of a traceback element""" prefix = "file://" prefix = "" f = tb.tb_frame if '__unittest' in f.f_globals: # this is the magical flag that prevents unittest internal # code from junking up the stacktrace return None filename = f.f_code.co_filename lineno = tb.tb_lineno linecache.checkcache(filename) function_name = f.f_code.co_name line_contents = linecache.getline(filename, lineno, f.f_globals).strip() return " %s line %s in %s\n %s" % ( termstyle.blue(prefix, self._relative_path(filename)), termstyle.bold(termstyle.cyan(lineno)), termstyle.cyan(function_name), line_contents)
def __init__(self, cfg_yaml_path = None, silent_mode = False, virtual_mode = False ): # super(InteractivePlatform, self).__init__() cmd.Cmd.__init__(self) self.virtual_mode = virtual_mode self.platform = CPlatform(silent_mode) if cfg_yaml_path is None: try: cfg_yaml_path = raw_input(termstyle.cyan("Please enter a readable .yaml configuration file path: ")) cfg_yaml_path = os.path.abspath(cfg_yaml_path) except KeyboardInterrupt: exit(-1) try: self.device_cfg = CDeviceCfg(cfg_yaml_path) self.platform.load_platform_data_from_file(self.device_cfg) if not virtual_mode: # if not virtual mode, try to establish a phyisical connection to platform self.platform.launch_connection(self.device_cfg) except Exception as inst: print(termstyle.magenta(inst)) exit(-1)
def do_exit(self, arg): """Quits the application""" print termstyle.cyan('Bye Bye!') return True
ret = self.trex.force_kill() if ret: print termstyle.green("*** End of scenario (TRex is not running now) ***") elif ret is None: print termstyle.magenta("*** End of scenario (TRex termination aborted) ***") else: print termstyle.red("*** End of scenario (TRex termination failed) ***") def do_exit(self, arg): """Quits the application""" print termstyle.cyan('Bye Bye!') return True if __name__ == "__main__": parser = ArgumentParser(description = termstyle.cyan('Run TRex client API demos and scenarios.'), usage = """client_interactive_example [options]""" ) parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0 \t (C) Cisco Systems Inc.\n') parser.add_argument("-t", "--trex-host", required = True, dest="trex_host", action="store", help="Specify the hostname or ip to connect with TRex server.", metavar="HOST" ) parser.add_argument("-p", "--trex-port", type=int, default = 8090, metavar="PORT", dest="trex_port", help="Select port on which the TRex server listens. Default port is 8090.", action="store") parser.add_argument("-m", "--maxhist", type=int, default = 100, metavar="SIZE", dest="hist_size", help="Specify maximum history size saved at client side. Default size is 100.", action="store") parser.add_argument("--verbose", dest="verbose", action="store_true", help="Switch ON verbose option at TRex client. Default is: OFF.", default = False ) args = parser.parse_args()
def __cbterminateIDLE(self, *args, **kwargs): print termstyle.cyan('__cbterminateIDLE') print termstyle.cyan(args) print termstyle.cyan(kwargs) return self.logout()
def color_parts(parts): """Adds colors to each part of the citation""" return parts._replace(title=green(parts.title), doi=cyan(parts.doi))