1
1
import os
2
2
from pathlib import Path
3
3
import re
4
+ from git import Repo
4
5
5
6
absolute_path = Path (__file__ ).resolve ().parents [2 ]
6
7
pattern_translated_strings = r'Translated:\s+(\d+)'
@@ -16,16 +17,20 @@ def run_git_command(command):
16
17
17
18
def get_translated_commit_strings (commit_hash ):
18
19
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
29
34
except Exception as e :
30
35
print (f"Error getting translated strings count: { e } " )
31
36
return 0
@@ -35,7 +40,13 @@ def get_difference_between_translated_commits_strings(commit_hash1, commit_hash2
35
40
try :
36
41
commit_hash1_count = get_translated_commit_strings (commit_hash1 )
37
42
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
39
44
except Exception as e :
40
45
print (f"Error calculating the difference between translated strings counts: { e } " )
41
46
return 0
47
+
48
+
49
+ hash1 = "69ff2f8a3141f5aad0f968e76675830a158660c6"
50
+ hash2 = "fa5d1cea27abe701398ee8fe7ee5ba285fafeee2"
51
+
52
+ print (get_difference_between_translated_commits_strings (hash1 , hash2 ))
0 commit comments