From 240fb08d3c8c34e14dca301e64cdb197f1af2a47 Mon Sep 17 00:00:00 2001 From: Guilherme Alves da Silva Date: Fri, 10 Nov 2023 14:59:03 -0300 Subject: [PATCH 1/7] Add function to compare translated strings between two commits --- .../get_translated_strings_between_commits.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/scripts/get_translated_strings_between_commits.py diff --git a/.github/scripts/get_translated_strings_between_commits.py b/.github/scripts/get_translated_strings_between_commits.py new file mode 100644 index 000000000..e5a6aebae --- /dev/null +++ b/.github/scripts/get_translated_strings_between_commits.py @@ -0,0 +1,41 @@ +import os +from pathlib import Path +import re + +absolute_path = Path(__file__).resolve().parents[2] +pattern_translated_strings = r'Translated:\s+(\d+)' + + +def run_git_command(command): + try: + return os.popen(command).read() + except Exception as e: + print(f"Error executing Git command: {e}") + return "" + + +def get_translated_commit_strings(commit_hash): + try: + changed_files = run_git_command(f"git diff-tree --no-commit-id --name-only {commit_hash} -r").split("\n") + changed_files.remove("") + changed_count = 0 + for file in changed_files: + file_path = absolute_path / file + output = os.popen(f"pocount {file_path}").read() + strings_match = re.search(pattern_translated_strings, output) + matched_strings = int(strings_match.group(1)) if strings_match else 0 + changed_count += matched_strings + return changed_count + except Exception as e: + print(f"Error getting translated strings count: {e}") + return 0 + + +def get_difference_between_translated_commits_strings(commit_hash1, commit_hash2): + try: + commit_hash1_count = get_translated_commit_strings(commit_hash1) + commit_hash2_count = get_translated_commit_strings(commit_hash2) + return abs(commit_hash1_count - commit_hash2_count) + except Exception as e: + print(f"Error calculating the difference between translated strings counts: {e}") + return 0 From c1a0135f899a985b6dda803531b87351b382db62 Mon Sep 17 00:00:00 2001 From: Guilherme Alves da Silva Date: Mon, 13 Nov 2023 13:27:31 -0300 Subject: [PATCH 2/7] testando outra forma de obter as strings do commit --- .../get_translated_strings_between_commits.py | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/scripts/get_translated_strings_between_commits.py b/.github/scripts/get_translated_strings_between_commits.py index e5a6aebae..2a1181496 100644 --- a/.github/scripts/get_translated_strings_between_commits.py +++ b/.github/scripts/get_translated_strings_between_commits.py @@ -1,6 +1,7 @@ import os from pathlib import Path import re +from git import Repo absolute_path = Path(__file__).resolve().parents[2] pattern_translated_strings = r'Translated:\s+(\d+)' @@ -16,16 +17,20 @@ def run_git_command(command): def get_translated_commit_strings(commit_hash): try: - changed_files = run_git_command(f"git diff-tree --no-commit-id --name-only {commit_hash} -r").split("\n") - changed_files.remove("") - changed_count = 0 - for file in changed_files: - file_path = absolute_path / file - output = os.popen(f"pocount {file_path}").read() - strings_match = re.search(pattern_translated_strings, output) - matched_strings = int(strings_match.group(1)) if strings_match else 0 - changed_count += matched_strings - return changed_count + commit_files = run_git_command(f"git switch {commit_hash} --detach") + with commit_files as cf: + output = os.popen(f"pocount *.po **/*.po").read() + print(output) + # changed_files = run_git_command(f"git diff-tree --no-commit-id --name-only {commit_hash} -r").split("\n") + # changed_files.remove("") + # changed_count = 0 + # for file in changed_files: + # file_path = absolute_path / file + # output = os.popen(f"pocount {file_path}").read() + # strings_match = re.search(pattern_translated_strings, output) + # matched_strings = int(strings_match.group(1)) if strings_match else 0 + # changed_count += matched_strings + # return changed_count except Exception as e: print(f"Error getting translated strings count: {e}") return 0 @@ -35,7 +40,13 @@ def get_difference_between_translated_commits_strings(commit_hash1, commit_hash2 try: commit_hash1_count = get_translated_commit_strings(commit_hash1) commit_hash2_count = get_translated_commit_strings(commit_hash2) - return abs(commit_hash1_count - commit_hash2_count) + return commit_hash1_count - commit_hash2_count except Exception as e: print(f"Error calculating the difference between translated strings counts: {e}") return 0 + + +hash1 = "69ff2f8a3141f5aad0f968e76675830a158660c6" +hash2 = "fa5d1cea27abe701398ee8fe7ee5ba285fafeee2" + +print(get_difference_between_translated_commits_strings(hash1, hash2)) From f5e5051f12d9e0657034f385ef499ee60b34c84e Mon Sep 17 00:00:00 2001 From: Guilherme Alves da Silva Date: Mon, 13 Nov 2023 13:31:08 -0300 Subject: [PATCH 3/7] retirando o contexto --- .github/scripts/get_translated_strings_between_commits.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/scripts/get_translated_strings_between_commits.py b/.github/scripts/get_translated_strings_between_commits.py index 2a1181496..98ad859b5 100644 --- a/.github/scripts/get_translated_strings_between_commits.py +++ b/.github/scripts/get_translated_strings_between_commits.py @@ -17,10 +17,9 @@ def run_git_command(command): def get_translated_commit_strings(commit_hash): try: - commit_files = run_git_command(f"git switch {commit_hash} --detach") - with commit_files as cf: - output = os.popen(f"pocount *.po **/*.po").read() - print(output) + run_git_command(f"git switch {commit_hash} --detach") + output = os.popen(f"pocount *.po **/*.po").read() + print(output) # changed_files = run_git_command(f"git diff-tree --no-commit-id --name-only {commit_hash} -r").split("\n") # changed_files.remove("") # changed_count = 0 From bbc6015eea78ba69410633932b3609cd6161f8e8 Mon Sep 17 00:00:00 2001 From: Guilherme Alves da Silva Date: Mon, 13 Nov 2023 13:59:21 -0300 Subject: [PATCH 4/7] =?UTF-8?q?mudando=20a=20forma=20como=20=C3=A9=20pego?= =?UTF-8?q?=20o=20commit=20strings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../get_translated_strings_between_commits.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/scripts/get_translated_strings_between_commits.py b/.github/scripts/get_translated_strings_between_commits.py index 98ad859b5..c2b394b38 100644 --- a/.github/scripts/get_translated_strings_between_commits.py +++ b/.github/scripts/get_translated_strings_between_commits.py @@ -18,18 +18,10 @@ def run_git_command(command): def get_translated_commit_strings(commit_hash): try: run_git_command(f"git switch {commit_hash} --detach") - output = os.popen(f"pocount *.po **/*.po").read() - print(output) - # changed_files = run_git_command(f"git diff-tree --no-commit-id --name-only {commit_hash} -r").split("\n") - # changed_files.remove("") - # changed_count = 0 - # for file in changed_files: - # file_path = absolute_path / file - # output = os.popen(f"pocount {file_path}").read() - # strings_match = re.search(pattern_translated_strings, output) - # matched_strings = int(strings_match.group(1)) if strings_match else 0 - # changed_count += matched_strings - # return changed_count + output = os.popen(f"pocount {absolute_path}/*.po {absolute_path}/**/*.po").read() + all_translated_results = re.findall(pattern_translated_strings, output, re.DOTALL) + translated_commit_strings = int(all_translated_results[-1]) + return translated_commit_strings except Exception as e: print(f"Error getting translated strings count: {e}") return 0 From a77da15eb04ceb840e58f04ab4059f9cc5aad682 Mon Sep 17 00:00:00 2001 From: Guilherme Alves da Silva Date: Mon, 13 Nov 2023 14:27:59 -0300 Subject: [PATCH 5/7] refatorando run_os_command e get_translated_strings_between_commits.py --- .../get_translated_strings_between_commits.py | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/.github/scripts/get_translated_strings_between_commits.py b/.github/scripts/get_translated_strings_between_commits.py index c2b394b38..f49aec98b 100644 --- a/.github/scripts/get_translated_strings_between_commits.py +++ b/.github/scripts/get_translated_strings_between_commits.py @@ -7,21 +7,21 @@ pattern_translated_strings = r'Translated:\s+(\d+)' -def run_git_command(command): +def run_os_command(command): try: return os.popen(command).read() except Exception as e: - print(f"Error executing Git command: {e}") + print(f"Error executing OS command: {e}") return "" def get_translated_commit_strings(commit_hash): try: - run_git_command(f"git switch {commit_hash} --detach") - output = os.popen(f"pocount {absolute_path}/*.po {absolute_path}/**/*.po").read() - all_translated_results = re.findall(pattern_translated_strings, output, re.DOTALL) - translated_commit_strings = int(all_translated_results[-1]) - return translated_commit_strings + run_os_command(f"git switch --force {commit_hash} --detach") + pocount_of_commit = run_os_command(f"pocount {absolute_path}/*.po {absolute_path}/**/*.po") + all_translated_results = re.findall(pattern_translated_strings, pocount_of_commit, re.DOTALL) + total_of_translated_commit_strings = int(all_translated_results[-1]) + return total_of_translated_commit_strings except Exception as e: print(f"Error getting translated strings count: {e}") return 0 @@ -35,9 +35,3 @@ def get_difference_between_translated_commits_strings(commit_hash1, commit_hash2 except Exception as e: print(f"Error calculating the difference between translated strings counts: {e}") return 0 - - -hash1 = "69ff2f8a3141f5aad0f968e76675830a158660c6" -hash2 = "fa5d1cea27abe701398ee8fe7ee5ba285fafeee2" - -print(get_difference_between_translated_commits_strings(hash1, hash2)) From 1ad887c79df5f13ceeebfb89ba7daa45b625ab38 Mon Sep 17 00:00:00 2001 From: Guilherme Alves da Silva Date: Mon, 13 Nov 2023 14:33:23 -0300 Subject: [PATCH 6/7] =?UTF-8?q?retirando=20dependencia=20n=C3=A3o=20usada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/scripts/get_translated_strings_between_commits.py | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/scripts/get_translated_strings_between_commits.py b/.github/scripts/get_translated_strings_between_commits.py index f49aec98b..f84097d9a 100644 --- a/.github/scripts/get_translated_strings_between_commits.py +++ b/.github/scripts/get_translated_strings_between_commits.py @@ -1,7 +1,6 @@ import os from pathlib import Path import re -from git import Repo absolute_path = Path(__file__).resolve().parents[2] pattern_translated_strings = r'Translated:\s+(\d+)' From 964d587718e90b4afb4d9c0499eda95b1144f167 Mon Sep 17 00:00:00 2001 From: Guilherme Alves da Silva Date: Mon, 13 Nov 2023 20:49:01 -0300 Subject: [PATCH 7/7] =?UTF-8?q?alterando=20biblioteca=20de=20manipula?= =?UTF-8?q?=C3=A7=C3=A3o=20com=20o=20sistema=20e=20retirando=20try=20excep?= =?UTF-8?q?ts=20desnecessarios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../get_translated_strings_between_commits.py | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/.github/scripts/get_translated_strings_between_commits.py b/.github/scripts/get_translated_strings_between_commits.py index f84097d9a..6e8a24ba5 100644 --- a/.github/scripts/get_translated_strings_between_commits.py +++ b/.github/scripts/get_translated_strings_between_commits.py @@ -1,4 +1,4 @@ -import os +import subprocess from pathlib import Path import re @@ -8,29 +8,21 @@ def run_os_command(command): try: - return os.popen(command).read() - except Exception as e: - print(f"Error executing OS command: {e}") - return "" + return subprocess.check_output(command, shell=True, text=True) + except subprocess.CalledProcessError as e: + print(f"Error executing command '{command}': {e}") + return None def get_translated_commit_strings(commit_hash): - try: - run_os_command(f"git switch --force {commit_hash} --detach") - pocount_of_commit = run_os_command(f"pocount {absolute_path}/*.po {absolute_path}/**/*.po") - all_translated_results = re.findall(pattern_translated_strings, pocount_of_commit, re.DOTALL) - total_of_translated_commit_strings = int(all_translated_results[-1]) - return total_of_translated_commit_strings - except Exception as e: - print(f"Error getting translated strings count: {e}") - return 0 + run_os_command(f"git switch --force {commit_hash} --detach") + pocount_of_commit = run_os_command(f"pocount {absolute_path}/*.po {absolute_path}/**/*.po") + all_translated_results = re.findall(pattern_translated_strings, pocount_of_commit, re.DOTALL) + total_of_translated_commit_strings = int(all_translated_results[-1]) + return total_of_translated_commit_strings def get_difference_between_translated_commits_strings(commit_hash1, commit_hash2): - try: - commit_hash1_count = get_translated_commit_strings(commit_hash1) - commit_hash2_count = get_translated_commit_strings(commit_hash2) - return commit_hash1_count - commit_hash2_count - except Exception as e: - print(f"Error calculating the difference between translated strings counts: {e}") - return 0 + commit_hash1_count = get_translated_commit_strings(commit_hash1) + commit_hash2_count = get_translated_commit_strings(commit_hash2) + return commit_hash1_count - commit_hash2_count