summaryrefslogtreecommitdiff
path: root/rbutil
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2020-06-21 08:40:31 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2020-07-26 09:56:20 +0200
commit1ed283de9c71540922e758417abde6dad98b8476 (patch)
tree455d1188e99025c46a17f064d64335ded92d1da8 /rbutil
parenta9c7bc7c9aa81fa394a1bf46aa6ff7ac536afe88 (diff)
downloadrockbox-1ed283de9c71540922e758417abde6dad98b8476.tar.gz
rockbox-1ed283de9c71540922e758417abde6dad98b8476.zip
rbutil: Update translation stats script.
- Update to Python3. - Change Qt tools to Qt5. - Cleanup. Change-Id: Icc9d9335518e8fba4a0c7a619527c8cdc087d59f
Diffstat (limited to 'rbutil')
-rwxr-xr-xrbutil/rbutilqt/langstats.py42
1 files changed, 17 insertions, 25 deletions
diff --git a/rbutil/rbutilqt/langstats.py b/rbutil/rbutilqt/langstats.py
index cb0bb3ffbd..7a1fc4f703 100755
--- a/rbutil/rbutilqt/langstats.py
+++ b/rbutil/rbutilqt/langstats.py
@@ -1,4 +1,4 @@
1#!/usr/bin/python 1#!/usr/bin/python3
2# __________ __ ___. 2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___ 3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
@@ -25,6 +25,7 @@ import sys
25import tempfile 25import tempfile
26import os 26import os
27import shutil 27import shutil
28import argparse
28 29
29# extend search path for gitscraper 30# extend search path for gitscraper
30sys.path.append(os.path.abspath(os.path.join( 31sys.path.append(os.path.abspath(os.path.join(
@@ -59,28 +60,19 @@ LANGBASE = "rbutil/rbutilqt/"
59GITPATHS = [LANGBASE] 60GITPATHS = [LANGBASE]
60 61
61 62
62def printhelp(): 63def main():
63 print("Usage:", sys.argv[0], "[options]") 64 parser = argparse.ArgumentParser(
64 print("Print translation statistics suitable for pasting in the wiki.") 65 description='Print translation statistics for pasting in the wiki.')
65 print("Options:") 66 parser.add_argument('-p', '--pretty', action='store_true',
66 print(" --pretty: display pretty output instead of wiki-style") 67 help='Display pretty output instead of wiki-style')
67 print(" --help: show this help")
68 68
69 args = parser.parse_args()
69 70
70def main(): 71 langstat(args.pretty)
71 if len(sys.argv) > 1:
72 if sys.argv[1] == '--help':
73 printhelp()
74 sys.exit(0)
75 if len(sys.argv) > 1:
76 if sys.argv[1] == '--pretty':
77 pretty = True
78 else:
79 pretty = False
80 langstat(pretty)
81 72
82 73
83def langstat(pretty=True): 74def langstat(pretty=True):
75 '''Get translation stats and print to stdout.'''
84 # get gitpaths to temporary folder 76 # get gitpaths to temporary folder
85 workfolder = tempfile.mkdtemp() + "/" 77 workfolder = tempfile.mkdtemp() + "/"
86 repo = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) 78 repo = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
@@ -91,11 +83,11 @@ def langstat(pretty=True):
91 83
92 projectfolder = workfolder + LANGBASE 84 projectfolder = workfolder + LANGBASE
93 # lupdate translations and drop all obsolete translations 85 # lupdate translations and drop all obsolete translations
94 subprocess.Popen(["lupdate-qt4", "-no-obsolete", "rbutilqt.pro"], 86 subprocess.Popen(["lupdate", "-no-obsolete", "rbutilqt.pro"],
95 stdout=subprocess.PIPE, stderr=subprocess.PIPE, 87 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
96 cwd=projectfolder).communicate() 88 cwd=projectfolder).communicate()
97 # lrelease translations to get status 89 # lrelease translations to get status
98 output = subprocess.Popen(["lrelease-qt4", "rbutilqt.pro"], 90 output = subprocess.Popen(["lrelease", "rbutilqt.pro"],
99 stdout=subprocess.PIPE, stderr=subprocess.PIPE, 91 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
100 cwd=projectfolder).communicate() 92 cwd=projectfolder).communicate()
101 lines = re.split(r"\n", output[0].decode()) 93 lines = re.split(r"\n", output[0].decode())
@@ -164,10 +156,10 @@ def langstat(pretty=True):
164 name = '(unknown)' 156 name = '(unknown)'
165 157
166 percent = (finished + unfinished) * 100. / (translations + ignored) 158 percent = (finished + unfinished) * 100. / (translations + ignored)
167 bar = "#" * int(percent / 10) 159 progress = "#" * int(percent / 10)
168 if (percent % 10) > 5: 160 if (percent % 10) > 5:
169 bar += "+" 161 progress += "+"
170 bar += " " * (10 - len(bar)) 162 progress += " " * (10 - len(progress))
171 if pretty: 163 if pretty:
172 fancylang = lang[0] + " " * (5 - len(lang[0])) 164 fancylang = lang[0] + " " * (5 - len(lang[0]))
173 else: 165 else:
@@ -177,7 +169,7 @@ def langstat(pretty=True):
177 "{:3}%% {} |" 169 "{:3}%% {} |"
178 % titlemax).format( 170 % titlemax).format(
179 name, fancylang, translations, finished, unfinished, 171 name, fancylang, translations, finished, unfinished,
180 ignored, tsdate, int(percent), bar)) 172 ignored, tsdate, int(percent), progress))
181 else: 173 else:
182 if percent > 90: 174 if percent > 90:
183 color = r'%GREEN%' 175 color = r'%GREEN%'
@@ -190,7 +182,7 @@ def langstat(pretty=True):
190 print("| %s | %s | %s | %s | %s | %s | %s | %s %i%% " 182 print("| %s | %s | %s | %s | %s | %s | %s | %s %i%% "
191 "%%ENDCOLOR%% %s |" % 183 "%%ENDCOLOR%% %s |" %
192 (name, fancylang, translations, finished, unfinished, 184 (name, fancylang, translations, finished, unfinished,
193 ignored, tsdate, color, percent, bar)) 185 ignored, tsdate, color, percent, progress))
194 186
195 if pretty: 187 if pretty:
196 print(delim) 188 print(delim)