diff --git a/Makefile b/Makefile index a44beac..a53694d 100644 --- a/Makefile +++ b/Makefile @@ -192,6 +192,16 @@ test_code_generator_template: db_restore_erplibre_base_db_template addons_instal .PHONY: test_code_generator_demo test_code_generator_demo: db_restore_erplibre_base_db_template addons_install_all_generated_demo clean_code_generator_template +.PHONY: test_code_generator_code +test_code_generator_code: clean_test + ./script/make.sh test_code_generator_template + ./script/make.sh test_code_generator_generation_other + +.PHONY: test_code_generator_code_i18n +test_code_generator_code_i18n: test_code_generator_code + ./script/make.sh test_code_generator_template + ./script/make.sh clean_code_generator_template + ############## # terminal # ############## @@ -208,10 +218,12 @@ format: format_code_generator format_code_generator_template .PHONY: format_code_generator format_code_generator: ./script/maintenance/black.sh ./addons/TechnoLibre_odoo-code-generator/ + #./script/maintenance/prettier_xml.sh ./addons/TechnoLibre_odoo-code-generator/ .PHONY: format_code_generator_template format_code_generator_template: ./script/maintenance/black.sh ./addons/TechnoLibre_odoo-code-generator-template/ + #./script/maintenance/prettier_xml.sh ./addons/TechnoLibre_odoo-code-generator-template/ ########### # clean # @@ -220,6 +232,10 @@ format_code_generator_template: clean_code_generator_template: ./script/repo_revert_git_diff_date_from_code_generator.py +.PHONY: clean_test +clean_test: + cd addons/OCA_server-tools; git stash; git clean -fd + ############ # docker # ############ diff --git a/script/make.sh b/script/make.sh new file mode 100755 index 0000000..c95d7cb --- /dev/null +++ b/script/make.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +echo "==$&%== Begin ${@}" +time make $@ +echo "==$&%== End ${@}" diff --git a/script/repo_revert_git_diff_date_from_code_generator.py b/script/repo_revert_git_diff_date_from_code_generator.py index 7a9793e..881cf89 100755 --- a/script/repo_revert_git_diff_date_from_code_generator.py +++ b/script/repo_revert_git_diff_date_from_code_generator.py @@ -35,42 +35,47 @@ def main(): config = get_config() # rex = r"\s+(?=\d{2}(?:\d{2})?-\d{1,2}-\d{1,2}\b)" rex = r"[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]" - path = "./addons/TechnoLibre_odoo-code-generator-template" - repo = git.Repo(path) - supported_ext = [".xml", ".pot", ".po"] - for diff in repo.index.diff(None, create_patch=True): - # if diff.change_type == "M": - file_path = diff.a_path - filename, file_extension = os.path.splitext(file_path) - if file_extension in supported_ext: - file_real_path = os.path.join(path, diff.a_path) - if not os.path.isfile(file_real_path): - continue - str_diff = repo.git.diff(diff.a_path) - patch = PatchSet(str_diff) - for modified_file in patch.modified_files: - lst_to_write = [] - for hunk in modified_file: - nb_line_source = len(hunk.source) - nb_line_target = len(hunk.target) - if nb_line_source != nb_line_target: - # TODO support different line - continue - # try: - # assert nb_line_source == nb_line_target, f"Not the same line of diff:\n{str_diff}" - # except Exception as e: - # print(e) - for i in range(nb_line_source): - result_source = re.split(rex, hunk.source[i]) - if i > len(hunk.target): - result_target = re.split(rex, hunk.target[i]) - else: - result_target = "" - if len(result_source) > 1 or len(result_target) > 1: - line_to_change = hunk.target_start + i - 1 - lst_to_write.append((line_to_change, hunk.source[i][1:])) - # rewrite - rewrite(file_real_path, lst_to_write) + lst_path = [ + "./addons/TechnoLibre_odoo-code-generator-template", + "./addons/OCA_server-tools", + ] + for path in lst_path: + repo = git.Repo(path) + supported_ext = [".xml", ".pot", ".po"] + for diff in repo.index.diff(None, create_patch=True): + # if diff.change_type == "M": + file_path = diff.a_path + filename, file_extension = os.path.splitext(file_path) + if file_extension in supported_ext: + file_real_path = os.path.join(path, diff.a_path) + if not os.path.isfile(file_real_path): + continue + str_diff = repo.git.diff(diff.a_path) + patch = PatchSet(str_diff) + for modified_file in patch.modified_files: + lst_to_write = [] + for hunk in modified_file: + nb_line_source = len(hunk.source) + nb_line_target = len(hunk.target) + if nb_line_source != nb_line_target: + # TODO support different line + _logger.warning(f"Source nb line different of target nb line for file {path}/{file_path}.") + continue + # try: + # assert nb_line_source == nb_line_target, f"Not the same line of diff:\n{str_diff}" + # except Exception as e: + # print(e) + for i in range(nb_line_source): + result_source = re.split(rex, hunk.source[i]) + if i > len(hunk.target): + result_target = re.split(rex, hunk.target[i]) + else: + result_target = "" + if len(result_source) > 1 or len(result_target) > 1: + line_to_change = hunk.target_start + i - 1 + lst_to_write.append((line_to_change, hunk.source[i][1:])) + # rewrite + rewrite(file_real_path, lst_to_write) def rewrite(file_path, lst_to_write):