forked from Ericsson/ecchronos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add options in ecctool to colored output - Issue Ericsson#527
- Loading branch information
Victor Cavichioli
committed
Mar 25, 2024
1 parent
c924e7e
commit e3ca625
Showing
10 changed files
with
236 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from colorama import Fore, init | ||
from supports_color import supportsColor | ||
|
||
init(autoreset=True) | ||
|
||
RED = Fore.RED | ||
GREEN = Fore.GREEN | ||
BLUE = Fore.BLUE | ||
YELLOW = Fore.YELLOW | ||
MAGENTA = Fore.MAGENTA | ||
CYAN = Fore.CYAN | ||
RESET = Fore.RESET | ||
DARK_MAGENTA = '\033[0;35m' | ||
|
||
color_map = { | ||
"Id": RED, | ||
"Host Id": RED, | ||
"Keyspace": CYAN, | ||
"Table": CYAN, | ||
"Status": MAGENTA, | ||
"Repaired(%)": MAGENTA, | ||
"Completed at": MAGENTA, | ||
"Next repair": MAGENTA, | ||
"Repair type": MAGENTA, | ||
"Start token": GREEN, | ||
"End token": RED, | ||
"Replicas": CYAN, | ||
"Repaired at": GREEN, | ||
"Repaired": CYAN, | ||
"Repair time taken": GREEN, | ||
"Config": MAGENTA, | ||
"UUID": GREEN, | ||
"FLOAT": CYAN, | ||
"DATETIME": GREEN, | ||
"INT": YELLOW, | ||
"TEXT": YELLOW, | ||
"COMPLETED": GREEN, | ||
"IN_QUEUE": CYAN, | ||
"BLOCKED": MAGENTA, | ||
"WARNING": YELLOW, | ||
"ERROR": RED, | ||
"ON_TIME": BLUE, | ||
"LATE": YELLOW, | ||
"OVERDUE": YELLOW, | ||
"Collection": MAGENTA | ||
} | ||
|
||
def color_str(field, color, field_type): | ||
if should_color(color): | ||
colored_str = color_map[field_type] + str(field) + RESET | ||
return colored_str | ||
return field | ||
|
||
def color_key(key, color): | ||
if should_color(color): | ||
colored_str = color_map[key] + str(key) + RESET | ||
return colored_str | ||
return key | ||
|
||
def color_index(summary, color): | ||
if should_color(color): | ||
colored_summary = [] | ||
for collum in summary: | ||
colored_collum = color_map[collum] + collum + RESET | ||
colored_summary.append(colored_collum) | ||
return colored_summary | ||
return summary | ||
|
||
def verify_system_compatibility() -> bool: | ||
if supportsColor.stdout: | ||
return True | ||
return False | ||
|
||
def should_color(color) -> bool: | ||
should_colorize = False | ||
if color == "auto": | ||
should_colorize = verify_system_compatibility() | ||
if color == "on": | ||
should_colorize = True | ||
return should_colorize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.