Update peass-parser.py
This commit is contained in:
parent
d57877077f
commit
7c275d50bc
@ -14,15 +14,15 @@ TITLE_CHARS = ['═', '╔', '╣', '╚']
|
|||||||
# Patterns for colors
|
# Patterns for colors
|
||||||
## The order is important, the first string colored with a color will be the one selected (the same string cannot be colored with different colors)
|
## The order is important, the first string colored with a color will be the one selected (the same string cannot be colored with different colors)
|
||||||
COLORS = {
|
COLORS = {
|
||||||
"REDYELLOW": [r"\x1b\[1;31;103m"],
|
"REDYELLOW": ['\x1b[1;31;103m'],
|
||||||
"RED": [r"\x1b\[1;31m"],
|
"RED": ['\x1b[1;31m'],
|
||||||
"GREEN": [r"\x1b\[1;32m"],
|
"GREEN": ['\x1b[1;32m'],
|
||||||
"YELLOW": [r"\x1b\[1;33m"],
|
"YELLOW": ['\x1b[1;33m'],
|
||||||
"BLUE": [r"\x1b\[1;34m"],
|
"BLUE": ['\x1b[1;34m'],
|
||||||
"MAGENTA": [r"\x1b\[1;95m", r"\x1b\[1;35m"],
|
"MAGENTA": ['\x1b[1;95m', '\x1b[1;35m'],
|
||||||
"CYAN": [r"\x1b\[1;36m", r"\x1b\[1;96m"],
|
"CYAN": ['\x1b[1;36m', '\x1b[1;96m'],
|
||||||
"LIGHT_GREY": [r"\x1b\[1;37m"],
|
"LIGHT_GREY": ['\x1b[1;37m'],
|
||||||
"DARKGREY": [r"\x1b\[1;90m"],
|
"DARKGREY": ['\x1b[1;90m'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -52,11 +52,23 @@ def get_colors(line: str) -> dict:
|
|||||||
for c,regexs in COLORS.items():
|
for c,regexs in COLORS.items():
|
||||||
colors[c] = []
|
colors[c] = []
|
||||||
for reg in regexs:
|
for reg in regexs:
|
||||||
for re_found in re.findall(reg+"(.+?)\x1b|$", line):
|
split_color = line.split(reg)
|
||||||
re_found = clean_colors(re_found.strip())
|
|
||||||
#Avoid having the same color for the same string
|
# Start from the index 1 as the index 0 isn't colored
|
||||||
if re_found and not any(re_found in values for values in colors.values()):
|
if split_color and len(split_color) > 1:
|
||||||
colors[c].append(re_found)
|
split_color = split_color[1:]
|
||||||
|
|
||||||
|
# For each potential color, find the string before any possible color terminatio
|
||||||
|
for potential_color_str in split_color:
|
||||||
|
color_str1 = potential_color_str.split('\x1b')[0]
|
||||||
|
color_str2 = potential_color_str.split("\[0")[0]
|
||||||
|
color_str = color_str1 if len(color_str1) < len(color_str2) else color_str2
|
||||||
|
|
||||||
|
if color_str:
|
||||||
|
color_str = clean_colors(color_str.strip())
|
||||||
|
#Avoid having the same color for the same string
|
||||||
|
if color_str and not any(color_str in values for values in colors.values()):
|
||||||
|
colors[c].append(color_str)
|
||||||
|
|
||||||
if not colors[c]:
|
if not colors[c]:
|
||||||
del colors[c]
|
del colors[c]
|
||||||
@ -94,6 +106,9 @@ def parse_line(line: str):
|
|||||||
|
|
||||||
global FINAL_JSON, C_SECTION, C_MAIN_SECTION, C_2_SECTION, C_3_SECTION
|
global FINAL_JSON, C_SECTION, C_MAIN_SECTION, C_2_SECTION, C_3_SECTION
|
||||||
|
|
||||||
|
if "Cron jobs" in line:
|
||||||
|
a=1
|
||||||
|
|
||||||
if is_section(line, TITLE1_PATTERN):
|
if is_section(line, TITLE1_PATTERN):
|
||||||
title = parse_title(line)
|
title = parse_title(line)
|
||||||
FINAL_JSON[title] = { "sections": {}, "lines": [], "infos": [] }
|
FINAL_JSON[title] = { "sections": {}, "lines": [], "infos": [] }
|
||||||
|
Loading…
Reference in New Issue
Block a user