feat: 美化输出 #27

Merged
ccyj merged 2 commits from feature/output-enhancement into main 2024-05-30 22:47:34 +08:00
Showing only changes of commit f798cf143c - Show all commits

View File

@ -172,79 +172,6 @@ def output_results(
print(txt_output) print(txt_output)
# def generate_text_content(results: Dict[str, List[Tuple[int, str]]]) -> str:
# """
# Generates a formatted text report for security analysis results.
# Args:
# results (Dict[str, List[Tuple[int, str]]]): The security analysis results categorized by risk levels.
# Returns:
# str: The formatted text report as a string.
# """
# text_output = (
# f"{Fore.CYAN}{Style.BRIGHT}Security Analysis Report{Style.RESET_ALL}\n"
# )
# text_output += "=" * 30 + "\n\n"
# for risk_level, entries in results.items():
# if entries and risk_level != "none":
# risk_color = {
# "high": Fore.RED,
# "medium": Fore.YELLOW,
# "low": Fore.GREEN,
# }.get(risk_level, Fore.WHITE)
# risk_title = {
# "High": "👹",
# "Medium": "👾",
# "Low": "👻",
# }
# text_output += f"{risk_color}{risk_level.capitalize()} Risk{risk_title[risk_level.capitalize()]}:{Style.RESET_ALL}\n"
# text_output += "-" * (len(risk_level) + 6) + "\n"
# for line_num, line in entries:
# text_output += f" Line {line_num}: {line}\n"
# text_output += "\n"
# return text_output
# def output_results(
# results: Dict[str, List[Tuple[int, str]]],
# output_format: str,
# output_file: Optional[str] = None,
# ) -> None:
# """
# Outputs the security analysis results in the specified format.
# Args:
# results (Dict[str, List[Tuple[int, str]]]): The security analysis results categorized by risk levels.
# output_format (str): The format to output the results in. Supported formats: "pdf", "html", "md", "txt".
# output_file (Optional[str]): The name of the file to save the output. If None, prints to the terminal.
# """
# OUTPUT_FORMATS = {"pdf", "html", "md", "txt"}
# if output_file:
# file_name, file_ext = os.path.splitext(output_file)
# if output_format not in OUTPUT_FORMATS:
# output_format = "txt"
# output_file = f"{file_name}.txt"
# results_dir = os.path.dirname(output_file)
# if not os.path.exists(results_dir) and results_dir != "":
# os.makedirs(results_dir)
# if output_format == "pdf":
# output_pdf(results, output_file)
# elif output_format == "html":
# output_html(results, output_file)
# elif output_format == "md":
# output_markdown(results, output_file)
# else: # Default to txt
# output_text(results, output_file)
# else:
# # If no output file is specified, default to text output to the terminal.
# txt_output = generate_text_content(results)
# print(txt_output)
def output_pdf(results: Dict[str, List[Tuple[int, str]]], file_name): def output_pdf(results: Dict[str, List[Tuple[int, str]]], file_name):
doc = SimpleDocTemplate(file_name, pagesize=letter) doc = SimpleDocTemplate(file_name, pagesize=letter)
story = [] story = []