mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Add colorful log output
Highlight the important operations (new, modified) in different colours.
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
import os
|
||||
import sys
|
||||
import pathlib
|
||||
from colorama import Style
|
||||
from colorama import Fore
|
||||
|
||||
__all__ = [
|
||||
"get_base_dir",
|
||||
@ -8,6 +11,7 @@ __all__ = [
|
||||
"stream_to_path",
|
||||
"ContentTypeException",
|
||||
"FileNotFoundException",
|
||||
"PrettyLogger",
|
||||
]
|
||||
|
||||
def get_base_dir(script_file):
|
||||
@ -26,8 +30,35 @@ def stream_to_path(response, to_path, chunk_size=1024**2):
|
||||
for chunk in response.iter_content(chunk_size=chunk_size):
|
||||
fd.write(chunk)
|
||||
|
||||
def isOutputPipe():
|
||||
"""Returns whether this program's output is attached to a pipe.
|
||||
"""
|
||||
return sys.stdout.isatty
|
||||
|
||||
class ContentTypeException(Exception):
|
||||
pass
|
||||
|
||||
class FileNotFoundException(Exception):
|
||||
pass
|
||||
|
||||
class PrettyLogger:
|
||||
|
||||
def __init__(self, logger):
|
||||
self.logger = logger
|
||||
|
||||
def modified_file(self, file_name):
|
||||
self.logger.info(f"{Fore.MAGENTA}{Style.BRIGHT}Modified {file_name}.{Style.RESET_ALL}")
|
||||
|
||||
def new_file(self, file_name):
|
||||
self.logger.info(f"{Fore.GREEN}{Style.BRIGHT}Created {file_name}.{Style.RESET_ALL}")
|
||||
|
||||
def ignored_file(self, file_name):
|
||||
self.logger.info(f"{Style.DIM}Ignored {file_name}.{Style.RESET_ALL}")
|
||||
|
||||
def starting_synchronizer(self, target_directory, synchronizer_name, subject=None):
|
||||
subject_str = f"{subject} " if subject else ""
|
||||
self.logger.info("")
|
||||
self.logger.info((
|
||||
f"{Fore.CYAN}{Style.BRIGHT}Synchronizing {subject_str}to {target_directory}"
|
||||
f" using the {synchronizer_name} synchronizer.{Style.RESET_ALL}"
|
||||
))
|
||||
|
Reference in New Issue
Block a user