def show_context(filename, line_number, show_line=3, is_back=False): if not show_line: return "" filename = check_filepath(PROJECT_DIRECTORY, filename) line_number = line_number if line_number else 0 line_start = int(line_number) - show_line if (int(line_number) - show_line) > 0 else 0 line_start = line_start if line_start else 1 line_end = int(line_start) + show_line + show_line lines = get_line(filename, "{},{}".format(line_start, line_end)) contents = "" i = 0 for line in lines: if not is_back: if line_start + i == int(line_number): logger_console.warning( "%4d: %s" % (line_start + i, line.replace("\n", ""))) else: logger_console.info("%4d: %s" % (line_start + i, line.replace("\n", ""))) contents += "%4d: %s" % (line_start + i, line) i += 1 return contents
def show_context(filename, line_number, show_line=3): filename = check_filepath(PROJECT_DIRECTORY, filename) line_start = int(line_number) - show_line line_end = int(line_number) + show_line lines = get_line(filename, "{},{}".format(line_start, line_end)) i = 0 for line in lines: i += 1 if i == (show_line + 1): logger_console.warning( "%4d: %s" % (line_start + i - 1, line.replace("\n", ""))) else: logger_console.info("%4d: %s" % (line_start + i - 1, line.replace("\n", "")))