[ADD] makefile generate code generation other and i18n

- clean test to stash git before copying data
- prettier_xml.sh in format
This commit is contained in:
Mathieu Benoit 2021-05-27 01:47:32 -04:00
parent 41e645d3fa
commit 6002309a68
3 changed files with 61 additions and 36 deletions

View file

@ -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 #
############

4
script/make.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
echo "==$&%== Begin ${@}"
time make $@
echo "==$&%== End ${@}"

View file

@ -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):