mirror of
https://github.com/Alex38Lyon/Synthese-PSM_LARRA.git
synced 2026-11-29 19:58:36 +00:00
Debug
This commit is contained in:
1 parent
6801ee5e91
commit
4b12ee1faf
38 files changed
+2773
-41697
No files matched your search
Binary file not shown.
Binary file not shown.
@@ -2,12 +2,13 @@
|
||||
!#############################################################################################
|
||||
!# #
|
||||
!# general_fonctions.py for pythStat.py #
|
||||
!# #
|
||||
!# #
|
||||
!#############################################################################################
|
||||
|
||||
Alex 2026 01 09
|
||||
|
||||
"""
|
||||
|
||||
import os, logging, sys, re, unicodedata
|
||||
from pathlib import Path
|
||||
|
||||
@@ -17,36 +18,39 @@ log = logging.getLogger("Logger")
|
||||
# Couleurs ANSI par niveau de log
|
||||
#################################################################################################
|
||||
COLOR_CODES = {
|
||||
logging.DEBUG: "\033[94m", # Bleu
|
||||
logging.INFO: "\033[92m", # Vert
|
||||
logging.WARNING: "\033[95m", # MAGENTA
|
||||
logging.ERROR: "\033[91m", # Rouge
|
||||
logging.DEBUG: "\033[94m", # Bleu
|
||||
logging.INFO: "\033[92m", # Vert
|
||||
logging.WARNING: "\033[95m", # MAGENTA
|
||||
logging.ERROR: "\033[91m", # Rouge
|
||||
logging.CRITICAL: "\033[1;91m", # Rouge vif
|
||||
}
|
||||
RESET = "\033[0m"
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# Codes de couleur ANSI
|
||||
class Colors:
|
||||
BLACK = '\033[90m'
|
||||
RED = '\033[91m'
|
||||
GREEN = '\033[92m'
|
||||
YELLOW = '\033[93m'
|
||||
BLUE = '\033[94m'
|
||||
MAGENTA = '\033[95m'
|
||||
CYAN = '\033[96m'
|
||||
WHITE = '\033[97m'
|
||||
|
||||
ERROR = '\033[91m'
|
||||
WARNING = '\033[95m'
|
||||
HEADER = '\033[1;94m'
|
||||
DEBUG = '\033[94m' # Bleu
|
||||
INFO = '\033[92m' # Vert
|
||||
CRITICAL = '\033[1;91m', # Rouge vif
|
||||
|
||||
ENDC = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
UNDERLINE = '\033[4m'
|
||||
BLACK = "\033[90m"
|
||||
RED = "\033[91m"
|
||||
GREEN = "\033[92m"
|
||||
YELLOW = "\033[93m"
|
||||
BLUE = "\033[94m"
|
||||
MAGENTA = "\033[95m"
|
||||
CYAN = "\033[96m"
|
||||
WHITE = "\033[97m"
|
||||
|
||||
ERROR = "\033[91m"
|
||||
WARNING = "\033[95m"
|
||||
HEADER = "\033[1;94m"
|
||||
DEBUG = "\033[94m" # Bleu
|
||||
INFO = "\033[92m" # Vert
|
||||
CRITICAL = ("\033[1;91m",) # Rouge vif
|
||||
|
||||
ENDC = "\033[0m"
|
||||
BOLD = "\033[95m\033[42m" # '\033[1m'
|
||||
BOLD2 = "\033[97m\033[42m"
|
||||
UNDERLINE = "\033[4m"
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# Coloration des messages d'aide d'arg #
|
||||
@@ -59,19 +63,19 @@ def colored_help(parser):
|
||||
parser (argparse.ArgumentParser): Le parseur d'arguments.
|
||||
Returns:
|
||||
None
|
||||
|
||||
|
||||
"""
|
||||
# Captures the help output
|
||||
help_text = parser.format_help()
|
||||
|
||||
|
||||
# Coloration des différentes parties
|
||||
colored_help_text = help_text.replace(
|
||||
'usage:', f'{Colors.ERROR}usage:{Colors.ENDC}'
|
||||
).replace(
|
||||
'options:', f'{Colors.GREEN}options:{Colors.ENDC}'
|
||||
).replace('positional arguments:', f'{Colors.BLUE}positional arguments:{Colors.ENDC}'
|
||||
).replace(', --help', f'{Colors.BLUE}, --help:{Colors.ENDC}'
|
||||
).replace('elp:', f'{Colors.BLUE}elp{Colors.ENDC}')
|
||||
colored_help_text = (
|
||||
help_text.replace("usage:", f"{Colors.ERROR}usage:{Colors.ENDC}")
|
||||
.replace("options:", f"{Colors.GREEN}options:{Colors.ENDC}")
|
||||
.replace("positional arguments:", f"{Colors.BLUE}positional arguments:{Colors.ENDC}")
|
||||
.replace(", --help", f"{Colors.BLUE}, --help:{Colors.ENDC}")
|
||||
.replace("elp:", f"{Colors.BLUE}elp{Colors.ENDC}")
|
||||
)
|
||||
|
||||
# Surligner les arguments
|
||||
# for action in parser._actions:
|
||||
@@ -79,11 +83,12 @@ def colored_help(parser):
|
||||
# # Colorer les options (--xyz)
|
||||
# for opt in action.option_strings:
|
||||
# colored_help_text = colored_help_text.replace(opt, f'{Colors.BLUE}{opt}{Colors.ENDC}').replace('--help', f'{Colors.BLUE}--help:{Colors.ENDC}')
|
||||
|
||||
|
||||
# Imprimer le texte coloré
|
||||
print(colored_help_text)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# Mise au format des noms #
|
||||
#################################################################################################
|
||||
@@ -98,34 +103,36 @@ def sanitize_filename(thName):
|
||||
|
||||
Returns:
|
||||
str: The cleaned and compatible string.
|
||||
|
||||
|
||||
"""
|
||||
# Unicode normalization to replace accented characters with their non-accented equivalents
|
||||
thName = unicodedata.normalize('NFKD', thName).encode('ASCII', 'ignore').decode('ASCII')
|
||||
thName = unicodedata.normalize("NFKD", thName).encode("ASCII", "ignore").decode("ASCII")
|
||||
|
||||
# Replace parentheses with underscores
|
||||
thName = thName.replace('(', '_').replace(')', '_')
|
||||
thName = thName.replace("(", "_").replace(")", "_")
|
||||
|
||||
# Replace illegal characters with an underscore
|
||||
thName = re.sub(r'[<>:"/\\|?*\']', '_', thName) # Illegal on Windows
|
||||
thName = re.sub(r'\s+', '_', thName) # Spaces to underscores
|
||||
thName = re.sub(r'[^a-zA-Z0-9._-]', '_', thName) # Keep only allowed chars
|
||||
thName = re.sub(r'[<>:"/\\|?*\']', "_", thName) # Illegal on Windows
|
||||
thName = re.sub(r"\s+", "_", thName) # Spaces to underscores
|
||||
thName = re.sub(r"[^a-zA-Z0-9._-]", "_", thName) # Keep only allowed chars
|
||||
|
||||
# Convert to lowercase, then capitalize the first letter
|
||||
# thName = thName.lower().capitalize()
|
||||
# thName = thName.capitalize()
|
||||
|
||||
|
||||
# Suppression des underscores en début et fin
|
||||
thName = thName.strip('_')
|
||||
thName = thName.strip("_")
|
||||
|
||||
return thName or "default_filename" # Avoid empty result
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# Supprime les codes ANSI (pour l'écriture dans les fichiers)
|
||||
#################################################################################################
|
||||
def strip_ansi_codes(text):
|
||||
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
||||
return ansi_escape.sub('', text)
|
||||
ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
|
||||
return ansi_escape.sub("", text)
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# Formatter pour la console avec couleurs
|
||||
@@ -136,6 +143,7 @@ class ConsoleFormatter(logging.Formatter):
|
||||
message = super().format(record)
|
||||
return f"{color}{message}{RESET}"
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# Formatter pour le fichier avec "!!!" sur les erreurs
|
||||
#################################################################################################
|
||||
@@ -152,10 +160,11 @@ class FileFormatter(logging.Formatter):
|
||||
args=(),
|
||||
exc_info=record.exc_info,
|
||||
func=record.funcName,
|
||||
sinfo=record.stack_info
|
||||
sinfo=record.stack_info,
|
||||
)
|
||||
return super().format(record_copy)
|
||||
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# Fonction de configuration du logger
|
||||
#################################################################################################
|
||||
@@ -163,9 +172,9 @@ def setup_logger(logfile="app.log", debug_log=False):
|
||||
logger = logging.getLogger("Logger")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.handlers.clear()
|
||||
|
||||
|
||||
min_level = logging.DEBUG if debug_log else logging.INFO
|
||||
|
||||
|
||||
# Console stderr handler — affichage à l'écran avec couleurs
|
||||
stderr_handler = logging.StreamHandler(sys.stderr)
|
||||
stderr_handler.setLevel(min_level)
|
||||
@@ -179,9 +188,10 @@ def setup_logger(logfile="app.log", debug_log=False):
|
||||
file_formatter = FileFormatter("%(asctime)s - %(levelname)s - %(message)s") # <-- Ta classe personnalisée
|
||||
file_handler.setFormatter(file_formatter)
|
||||
logger.addHandler(file_handler)
|
||||
|
||||
|
||||
return logger
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# fonction pour réduire l'affichage des chemins long #
|
||||
#################################################################################################
|
||||
@@ -233,7 +243,3 @@ def safe_relpath(path, base_dir=None, max_depth=3, max_name_len=50, prefix="~"):
|
||||
return os.path.join(*parts)
|
||||
except Exception:
|
||||
return name
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
"""
|
||||
!#############################################################################################!
|
||||
!# #!
|
||||
!# global_data.py for pythStat.py #!
|
||||
!# #!
|
||||
!# #!
|
||||
!# global_data.py for pythStat.py #!
|
||||
!# #!
|
||||
!#############################################################################################!
|
||||
"""
|
||||
|
||||
Version = "2026.09.25"
|
||||
Version = "2026.10.18"
|
||||
|
||||
#################################################################################################
|
||||
|
||||
# error_count = 0 # Compteur d'erreurs
|
||||
debug_log = False
|
||||
|
||||
outputFilename = "readme"
|
||||
outputFilename = "readme"
|
||||
Reference in new issue
Block a user