8000 testando outra forma de obter as strings do commit · python/python-docs-pt-br@c1a0135 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1a0135

Browse files
committed
testando outra forma de obter as strings do commit
1 parent e608405 commit c1a0135

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed
Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from pathlib import Path
33
import re
4+
from git import Repo
45

56
absolute_path = Path(__file__).resolve().parents[2]
67
pattern_translated_strings = r'Translated:\s+(\d+)'
@@ -16,16 +17,20 @@ def run_git_command(command):
1617

1718
def get_translated_commit_strings(commit_hash):
1819
try:
19-
changed_files = run_git_command(f"git diff-tree --no-commit-id --name-only {commit_hash} -r").split("\n")
20-
changed_files.remove("")
21-
changed_count = 0
22-
for file in changed_files:
23-
file_path = absolute_path / file
24-
output = os.popen(f"pocount {file_path}").read()
25-
strings_match = re.search(pattern_translated_strings, output)
26-
matched_strings = int(strings_match.group(1)) if strings_match else 0
27-
changed_count += matched_strings
28-
return changed_count
20+
commit_files = run_git_command(f"git switch {commit_hash} --detach")
21+
with commit_files as cf:
22+
output = os.popen(f"pocount *.po **/*.po").read()
23+
print(output)
24+
# changed_files = run_git_command(f"git diff-tree --no-commit-id --name-only {commit_hash} -r").split("\n")
25+
# changed_files.remove("")
26+
# changed_count = 0
27+
# for file in changed_files:
28+
# file_path = absolute_path / file
29+
# output = os.popen(f"pocount {file_path}").read()
30+
# strings_match = re.search(pattern_translated_strings, output)
31+
# matched_strings = int(strings_match.group(1)) if strings_match else 0
32+
# changed_count += matched_strings
33+
# return changed_count
2934
except Exception as e:
3035
print(f"Error getting translated strings count: {e}")
3136
return 0
@@ -35,7 +40,13 @@ def get_difference_between_translated_commits_strings(commit_hash1, commit_hash2
3540
try:
3641
commit_hash1_count = get_translated_commit_strings(commit_hash1)
3742
commit_hash2_count = get_translated_commit_strings(commit_hash2)
38-
return abs(commit_hash1_count - commit_hash2_count)
43+
return commit_hash1_count - commit_hash2_count
3944
except Exception as e:
4045
print(f"Error calculating the difference between translated strings counts: {e}")
4146
return 0
47+
48+
49+
hash1 = "69ff2f8a3141f5aad0f968e76675830a158660c6"
50+
hash2 = "fa5d1cea27abe701398ee8fe7ee5ba285fafeee2"
51+
52+
print(get_difference_between_translated_commits_strings(hash1, hash2))

0 commit comments

Comments
 (0)
0