add colored output

This commit is contained in:
MLH
2024-12-10 02:19:58 +01:00
parent 2605923e17
commit 2be1eb8fdc

View File

@ -4,6 +4,13 @@ import yaml
import re
import sys
# ANSI escape sequences for colors
class Colors:
CYAN = '\033[96m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
RESET = '\033[0m'
# Global variable to track errors
errorList = {"copies": 0, "modifications": 0, "copyWarnings": 0, "modWarnings": 0}
@ -134,7 +141,7 @@ def copySources(config, destinationDirectory):
errorList["copies"] += 1
continue
print(f"\nSource file & folder copy/replace process completed with {errorList['copies']} errors and {errorList['copyWarnings']} warnings.\n")
print(f"\nSource file & folder copy/replace process completed with {Colors.RED}{errorList['copies']} errors{Colors.RESET} and {Colors.YELLOW}{errorList['copyWarnings']} warnings{Colors.RESET}.\n")
def modifyFiles(config, destinationDirectory):
@ -218,7 +225,7 @@ def modifyFiles(config, destinationDirectory):
errorList["modifications"] += 1
continue
print(f"\nFile modification process completed with {errorList['modifications']} errors and {errorList['modWarnings']} warnings.\n")
print(f"\nFile modification process completed with {Colors.RED}{errorList['modifications']} errors{Colors.RESET} and {Colors.YELLOW}{errorList['modWarnings']} warnings{Colors.RESET}.\n")
def main():
@ -244,17 +251,17 @@ def main():
modifyFiles(config, destinationDirectory)
# Print results
print(f'\nTotal successful copies: {results["copies"]}')
print(f'Total file modifications: {results["modifications"]}')
print(f'\n{Colors.GREEN}Total successful copies: {results["copies"]}')
print(f'Total file modifications: {results["modifications"]}{Colors.RESET}')
if errorList["copies"] > 0 or errorList["modifications"] > 0:
print("Errors occurred during the process. Check the output for details.")
print(f"{Colors.RED}Errors occurred during the process. Check the output for details.")
print(f"Total copy errors: {errorList['copies']}")
print(f"Total modification errors: {errorList['modifications']}")
print(f"Total modification errors: {errorList['modifications']}{Colors.RESET}")
elif errorList["copyWarnings"] > 0 or errorList["modWarnings"] > 0:
print(f"All operations in {destinationDirectory} from {configPath} completed successfully! But there were {errorList['modWarnings'] + errorList['copyWarnings']} warnings. Mybe you should check them.")
print(f"{Colors.YELLOW}All operations in {destinationDirectory} from {configPath} completed successfully! But there were {errorList['modWarnings'] + errorList['copyWarnings']} warnings. Maybe you should check them.{Colors.RESET}")
else:
print(f"All operations in {destinationDirectory} from {configPath} completed successfully!")
print(f"{Colors.GREEN}All operations in {destinationDirectory} from {configPath} completed successfully!{Colors.RESET}")
if __name__ == '__main__':