1
0
Fork 0
forked from len0rd/rockbox

rbutil: Update translation stats script.

- Update to Python3.
- Change Qt tools to Qt5.
- Cleanup.

Change-Id: Icc9d9335518e8fba4a0c7a619527c8cdc087d59f
This commit is contained in:
Dominik Riebeling 2020-06-21 08:40:31 +02:00
parent a9c7bc7c9a
commit 1ed283de9c

View file

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# __________ __ ___. # __________ __ ___.
# Open \______ \ ____ ____ | | _\_ |__ _______ ___ # Open \______ \ ____ ____ | | _\_ |__ _______ ___
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
@ -25,6 +25,7 @@ import sys
import tempfile import tempfile
import os import os
import shutil import shutil
import argparse
# extend search path for gitscraper # extend search path for gitscraper
sys.path.append(os.path.abspath(os.path.join( sys.path.append(os.path.abspath(os.path.join(
@ -59,28 +60,19 @@ LANGBASE = "rbutil/rbutilqt/"
GITPATHS = [LANGBASE] GITPATHS = [LANGBASE]
def printhelp():
print("Usage:", sys.argv[0], "[options]")
print("Print translation statistics suitable for pasting in the wiki.")
print("Options:")
print(" --pretty: display pretty output instead of wiki-style")
print(" --help: show this help")
def main(): def main():
if len(sys.argv) > 1: parser = argparse.ArgumentParser(
if sys.argv[1] == '--help': description='Print translation statistics for pasting in the wiki.')
printhelp() parser.add_argument('-p', '--pretty', action='store_true',
sys.exit(0) help='Display pretty output instead of wiki-style')
if len(sys.argv) > 1:
if sys.argv[1] == '--pretty': args = parser.parse_args()
pretty = True
else: langstat(args.pretty)
pretty = False
langstat(pretty)
def langstat(pretty=True): def langstat(pretty=True):
'''Get translation stats and print to stdout.'''
# get gitpaths to temporary folder # get gitpaths to temporary folder
workfolder = tempfile.mkdtemp() + "/" workfolder = tempfile.mkdtemp() + "/"
repo = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) repo = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
@ -91,11 +83,11 @@ def langstat(pretty=True):
projectfolder = workfolder + LANGBASE projectfolder = workfolder + LANGBASE
# lupdate translations and drop all obsolete translations # lupdate translations and drop all obsolete translations
subprocess.Popen(["lupdate-qt4", "-no-obsolete", "rbutilqt.pro"], subprocess.Popen(["lupdate", "-no-obsolete", "rbutilqt.pro"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cwd=projectfolder).communicate() cwd=projectfolder).communicate()
# lrelease translations to get status # lrelease translations to get status
output = subprocess.Popen(["lrelease-qt4", "rbutilqt.pro"], output = subprocess.Popen(["lrelease", "rbutilqt.pro"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cwd=projectfolder).communicate() cwd=projectfolder).communicate()
lines = re.split(r"\n", output[0].decode()) lines = re.split(r"\n", output[0].decode())
@ -164,10 +156,10 @@ def langstat(pretty=True):
name = '(unknown)' name = '(unknown)'
percent = (finished + unfinished) * 100. / (translations + ignored) percent = (finished + unfinished) * 100. / (translations + ignored)
bar = "#" * int(percent / 10) progress = "#" * int(percent / 10)
if (percent % 10) > 5: if (percent % 10) > 5:
bar += "+" progress += "+"
bar += " " * (10 - len(bar)) progress += " " * (10 - len(progress))
if pretty: if pretty:
fancylang = lang[0] + " " * (5 - len(lang[0])) fancylang = lang[0] + " " * (5 - len(lang[0]))
else: else:
@ -177,7 +169,7 @@ def langstat(pretty=True):
"{:3}%% {} |" "{:3}%% {} |"
% titlemax).format( % titlemax).format(
name, fancylang, translations, finished, unfinished, name, fancylang, translations, finished, unfinished,
ignored, tsdate, int(percent), bar)) ignored, tsdate, int(percent), progress))
else: else:
if percent > 90: if percent > 90:
color = r'%GREEN%' color = r'%GREEN%'
@ -190,7 +182,7 @@ def langstat(pretty=True):
print("| %s | %s | %s | %s | %s | %s | %s | %s %i%% " print("| %s | %s | %s | %s | %s | %s | %s | %s %i%% "
"%%ENDCOLOR%% %s |" % "%%ENDCOLOR%% %s |" %
(name, fancylang, translations, finished, unfinished, (name, fancylang, translations, finished, unfinished,
ignored, tsdate, color, percent, bar)) ignored, tsdate, color, percent, progress))
if pretty: if pretty:
print(delim) print(delim)