|
1 |
| -import os |
| 1 | +import subprocess |
2 | 2 | from pathlib import Path
|
3 | 3 | import re
|
4 | 4 |
|
|
8 | 8 |
|
9 | 9 | def run_os_command(command):
|
10 | 10 | try:
|
11 |
| - return os.popen(command).read() |
12 |
| - except Exception as e: |
13 |
| - print(f"Error executing OS command: {e}") |
14 |
| - return "" |
| 11 | + return subprocess.check_output(command, shell=True, text=True) |
| 12 | + except subprocess.CalledProcessError as e: |
| 13 | + print(f"Error executing command '{command}': {e}") |
| 14 | + return None |
15 | 15 |
|
16 | 16 |
|
17 | 17 | def get_translated_commit_strings(commit_hash):
|
18 |
| - try: |
19 |
| - run_os_command(f"git switch --force {commit_hash} --detach") |
20 |
| - pocount_of_commit = run_os_command(f"pocount {absolute_path}/*.po {absolute_path}/**/*.po") |
21 |
| - all_translated_results = re.findall(pattern_translated_strings, pocount_of_commit, re.DOTALL) |
22 |
| - total_of_translated_commit_strings = int(all_translated_results[-1]) |
23 |
| - return total_of_translated_commit_strings |
24 |
| - except Exception as e: |
25 |
| - print(f"Error getting translated strings count: {e}") |
26 |
| - return 0 |
| 18 | + run_os_command(f"git switch --force {commit_hash} --detach") |
| 19 | + pocount_of_commit = run_os_command(f"pocount {absolute_path}/*.po {absolute_path}/**/*.po") |
| 20 | + all_translated_results = re.findall(pattern_translated_strings, pocount_of_commit, re.DOTALL) |
| 21 | + total_of_translated_commit_strings = int(all_translated_results[-1]) |
| 22 | + return total_of_translated_commit_strings |
27 | 23 |
|
28 | 24 |
|
29 | 25 | def get_difference_between_translated_commits_strings(commit_hash1, commit_hash2):
|
30 |
| - try: |
31 |
| - commit_hash1_count = get_translated_commit_strings(commit_hash1) |
32 |
| - commit_hash2_count = get_translated_commit_strings(commit_hash2) |
33 |
| - return commit_hash1_count - commit_hash2_count |
34 |
| - except Exception as e: |
35 |
| - print(f"Error calculating the difference between translated strings counts: {e}") |
36 |
| - return 0 |
| 26 | + commit_hash1_count = get_translated_commit_strings(commit_hash1) |
| 27 | + commit_hash2_count = get_translated_commit_strings(commit_hash2) |
| 28 | + return commit_hash1_count - commit_hash2_count |
0 commit comments