[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:
parent
41e645d3fa
commit
6002309a68
3 changed files with 61 additions and 36 deletions
16
Makefile
16
Makefile
|
|
@ -192,6 +192,16 @@ test_code_generator_template: db_restore_erplibre_base_db_template addons_instal
|
||||||
.PHONY: test_code_generator_demo
|
.PHONY: test_code_generator_demo
|
||||||
test_code_generator_demo: db_restore_erplibre_base_db_template addons_install_all_generated_demo clean_code_generator_template
|
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 #
|
# terminal #
|
||||||
##############
|
##############
|
||||||
|
|
@ -208,10 +218,12 @@ format: format_code_generator format_code_generator_template
|
||||||
.PHONY: format_code_generator
|
.PHONY: format_code_generator
|
||||||
format_code_generator:
|
format_code_generator:
|
||||||
./script/maintenance/black.sh ./addons/TechnoLibre_odoo-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
|
.PHONY: format_code_generator_template
|
||||||
format_code_generator_template:
|
format_code_generator_template:
|
||||||
./script/maintenance/black.sh ./addons/TechnoLibre_odoo-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 #
|
# clean #
|
||||||
|
|
@ -220,6 +232,10 @@ format_code_generator_template:
|
||||||
clean_code_generator_template:
|
clean_code_generator_template:
|
||||||
./script/repo_revert_git_diff_date_from_code_generator.py
|
./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 #
|
# docker #
|
||||||
############
|
############
|
||||||
|
|
|
||||||
4
script/make.sh
Executable file
4
script/make.sh
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
echo "==$&%== Begin ${@}"
|
||||||
|
time make $@
|
||||||
|
echo "==$&%== End ${@}"
|
||||||
|
|
@ -35,42 +35,47 @@ def main():
|
||||||
config = get_config()
|
config = get_config()
|
||||||
# rex = r"\s+(?=\d{2}(?:\d{2})?-\d{1,2}-\d{1,2}\b)"
|
# 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]"
|
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"
|
lst_path = [
|
||||||
repo = git.Repo(path)
|
"./addons/TechnoLibre_odoo-code-generator-template",
|
||||||
supported_ext = [".xml", ".pot", ".po"]
|
"./addons/OCA_server-tools",
|
||||||
for diff in repo.index.diff(None, create_patch=True):
|
]
|
||||||
# if diff.change_type == "M":
|
for path in lst_path:
|
||||||
file_path = diff.a_path
|
repo = git.Repo(path)
|
||||||
filename, file_extension = os.path.splitext(file_path)
|
supported_ext = [".xml", ".pot", ".po"]
|
||||||
if file_extension in supported_ext:
|
for diff in repo.index.diff(None, create_patch=True):
|
||||||
file_real_path = os.path.join(path, diff.a_path)
|
# if diff.change_type == "M":
|
||||||
if not os.path.isfile(file_real_path):
|
file_path = diff.a_path
|
||||||
continue
|
filename, file_extension = os.path.splitext(file_path)
|
||||||
str_diff = repo.git.diff(diff.a_path)
|
if file_extension in supported_ext:
|
||||||
patch = PatchSet(str_diff)
|
file_real_path = os.path.join(path, diff.a_path)
|
||||||
for modified_file in patch.modified_files:
|
if not os.path.isfile(file_real_path):
|
||||||
lst_to_write = []
|
continue
|
||||||
for hunk in modified_file:
|
str_diff = repo.git.diff(diff.a_path)
|
||||||
nb_line_source = len(hunk.source)
|
patch = PatchSet(str_diff)
|
||||||
nb_line_target = len(hunk.target)
|
for modified_file in patch.modified_files:
|
||||||
if nb_line_source != nb_line_target:
|
lst_to_write = []
|
||||||
# TODO support different line
|
for hunk in modified_file:
|
||||||
continue
|
nb_line_source = len(hunk.source)
|
||||||
# try:
|
nb_line_target = len(hunk.target)
|
||||||
# assert nb_line_source == nb_line_target, f"Not the same line of diff:\n{str_diff}"
|
if nb_line_source != nb_line_target:
|
||||||
# except Exception as e:
|
# TODO support different line
|
||||||
# print(e)
|
_logger.warning(f"Source nb line different of target nb line for file {path}/{file_path}.")
|
||||||
for i in range(nb_line_source):
|
continue
|
||||||
result_source = re.split(rex, hunk.source[i])
|
# try:
|
||||||
if i > len(hunk.target):
|
# assert nb_line_source == nb_line_target, f"Not the same line of diff:\n{str_diff}"
|
||||||
result_target = re.split(rex, hunk.target[i])
|
# except Exception as e:
|
||||||
else:
|
# print(e)
|
||||||
result_target = ""
|
for i in range(nb_line_source):
|
||||||
if len(result_source) > 1 or len(result_target) > 1:
|
result_source = re.split(rex, hunk.source[i])
|
||||||
line_to_change = hunk.target_start + i - 1
|
if i > len(hunk.target):
|
||||||
lst_to_write.append((line_to_change, hunk.source[i][1:]))
|
result_target = re.split(rex, hunk.target[i])
|
||||||
# rewrite
|
else:
|
||||||
rewrite(file_real_path, lst_to_write)
|
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):
|
def rewrite(file_path, lst_to_write):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue