From 8ab3883b225a511384aed3de8245f47b6eee3927 Mon Sep 17 00:00:00 2001 From: Mathieu Benoit Date: Thu, 6 Nov 2025 03:40:46 -0500 Subject: [PATCH] [IMP] script format: support format detected all repo --- script/maintenance/format_file_to_commit.py | 118 ++++++++++++-------- 1 file changed, 73 insertions(+), 45 deletions(-) diff --git a/script/maintenance/format_file_to_commit.py b/script/maintenance/format_file_to_commit.py index 05d900c..de818c0 100755 --- a/script/maintenance/format_file_to_commit.py +++ b/script/maintenance/format_file_to_commit.py @@ -2,6 +2,7 @@ # © 2021-2025 TechnoLibre (http://www.technolibre.ca) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +import os import subprocess IGNORE_EXTENSION = [] @@ -15,62 +16,89 @@ def execute_shell(cmd): def get_modified_files(): lst_cmd_git_status = ["git", "status", "--porcelain"] - print(" ".join(lst_cmd_git_status)) + lst_cmd_git_status_repo = [ + ".venv.erplibre/bin/repo", + "forall", + "-p", + "-c", + "git status -s", + ] try: + print(" ".join(lst_cmd_git_status)) result = subprocess.run( lst_cmd_git_status, capture_output=True, text=True, check=True, ) - lines = result.stdout.strip().split("\n") + lines_local = result.stdout.strip().split("\n") + + lst_lines = [(".", lines_local)] + + print(" ".join(lst_cmd_git_status_repo)) + + result = subprocess.run( + lst_cmd_git_status_repo, + capture_output=True, + text=True, + check=True, + ) + lines_project = result.stdout.strip().split("\n\n") + for str_project_line in lines_project: + line_repo = str_project_line.split("\n") + projet_name = line_repo[0] + lines_local = line_repo[1:] + directory_project = projet_name[len("project ") :] + lst_lines.append((directory_project, lines_local)) modified_files = [] - for line in lines: - if not line: - continue + for directory, lines in lst_lines: + for line in lines: + if not line: + continue - try: - has_space = False - file_path_space = "" - if '"' in line: - has_space = True - file_path_space = line[ - line.index('"') + 1 : line.rindex('"') - ] - line = line.replace(f'"{file_path_space}"', "replace") - if "->" in line: - # Example : M file_01 -> file_02 - status, old_file_path, code, file_path = ( - line.strip().replace(" ", " ").split(" ") - ) + try: + has_space = False + file_path_space = "" + if '"' in line: + has_space = True + file_path_space = line[ + line.index('"') + 1 : line.rindex('"') + ] + line = line.replace(f'"{file_path_space}"', "replace") + if "->" in line: + # Example : M file_01 -> file_02 + status, old_file_path, code, file_path = ( + line.strip().replace(" ", " ").split(" ") + ) + else: + # Example : M file_01 + status, file_path = ( + line.strip().replace(" ", " ").split(" ") + ) + if has_space: + file_path = file_path_space + file_path = os.path.join(directory, file_path) + + except Exception as e: + print(f"'{line}'") + raise e + + if ( + status == "M" + or status == "A" + or status == "AM" + or status == "MM" + or status == "R" + or status == "RM" + or status == "??" + ): + modified_files.append((status, file_path)) + elif status == "D": + # Ignore to format removed file + pass else: - # Example : M file_01 - status, file_path = ( - line.strip().replace(" ", " ").split(" ") - ) - if has_space: - file_path = file_path_space - - except Exception as e: - print(f"'{line}'") - raise e - - if ( - status == "M" - or status == "A" - or status == "AM" - or status == "MM" - or status == "R" - or status == "RM" - or status == "??" - ): - modified_files.append((status, file_path)) - elif status == "D": - # Ignore to format removed file - pass - else: - print(f"Not supported status '{status}'") + print(f"Not supported status '{status}'") return modified_files except subprocess.CalledProcessError as e: