1
0
Fork 0
forked from len0rd/rockbox

rbutil: Fix langstat script.

Change-Id: I323b0e8dbf87f1d53881f5b89f26c5906796fde4
This commit is contained in:
Dominik Riebeling 2022-03-27 12:56:34 +02:00
parent aaf0f1c371
commit 493dce212d

View file

@ -53,7 +53,7 @@ LANGS = {
} }
LANGBASE = "rbutil/rbutilqt/" LANGBASE = "utils/rbutilqt"
# Paths and files to retrieve from svn. # Paths and files to retrieve from svn.
# This is a mixed list, holding both paths and filenames. # This is a mixed list, holding both paths and filenames.
# Get cpp sources as well for lupdate to work. # Get cpp sources as well for lupdate to work.
@ -75,24 +75,26 @@ def main():
def langstat(pretty=True, tree=None): def langstat(pretty=True, tree=None):
'''Get translation stats and print to stdout.''' '''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__), "../.."))
if tree is None: if tree is None:
tree = gitscraper.get_refs(repo)['HEAD'] tree = gitscraper.get_refs(repo)['HEAD']
filesprops = gitscraper.scrape_files( filesprops = gitscraper.scrape_files(
repo, tree, GITPATHS, dest=workfolder, repo, tree, GITPATHS, dest=workfolder,
timestamp_files=["rbutil/rbutilqt/lang"]) timestamp_files=[f"{LANGBASE}/lang"])
projectfolder = workfolder + LANGBASE projectfolder = os.path.join(workfolder, LANGBASE)
# lupdate translations and drop all obsolete translations # lupdate translations and drop all obsolete translations
subprocess.Popen(["lupdate", "-no-obsolete", "rbutilqt.pro"], subprocess.Popen(["lupdate", "-no-obsolete", projectfolder, "-ts"]
+ [f"lang/rbutil_{l}.ts" for l in LANGS],
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", "rbutilqt.pro"], output = subprocess.Popen(["lrelease"]
+ [f"lang/rbutil_{l}.ts" for l in LANGS],
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 = output[0].decode().split("\n")
re_updating = re.compile(r"^Updating.*") re_updating = re.compile(r"^Updating.*")
re_generated = re.compile(r"Generated.*") re_generated = re.compile(r"Generated.*")
@ -124,9 +126,8 @@ def langstat(pretty=True, tree=None):
print(head) print(head)
print(delim) print(delim)
else: else:
rev = "%s (%s)" % ( rev = f"{tree} {gitscraper.get_file_timestamp(repo, tree, '.')}"
tree, gitscraper.get_file_timestamp(repo, tree, ".")) print(f"| *Translation status as of revision {rev}* ||||||||")
print("| *Translation status as of revision %s* ||||||||" % rev)
print("| *Language* | *Language Code* | *Translations* " print("| *Language* | *Language Code* | *Translations* "
"| *Finished* | *Unfinished* | *Untranslated* | *Updated* " "| *Finished* | *Unfinished* | *Untranslated* | *Updated* "
"| *Done* |") "| *Done* |")
@ -135,7 +136,7 @@ def langstat(pretty=True, tree=None):
for i, line in enumerate(lines): for i, line in enumerate(lines):
if re_updating.search(line): if re_updating.search(line):
lang = re_qmlang.findall(line) lang = re_qmlang.findall(line)
tsfile = "rbutil/rbutilqt/lang/%s.ts" % re_qmbase.findall(line)[0] tsfile = f"{LANGBASE}/lang/{re_qmbase.findall(line)[0]}.ts"
tsdate = filesprops[1][tsfile] tsdate = filesprops[1][tsfile]
line = lines[i + 1] line = lines[i + 1]
@ -166,11 +167,10 @@ def langstat(pretty=True, tree=None):
else: else:
fancylang = lang[0] fancylang = lang[0]
if pretty: if pretty:
print(("| {:%i} | {:5} | {:3} | {:3} | {:3} | {:3} | {:25} | " print(f"| {name:{titlemax}} | {fancylang:5} | "
"{:3}%% {} |" f"{translations:3} | {finished:3} | {unfinished:3} | "
% titlemax).format( f"{ignored:3} | {tsdate:25} | "
name, fancylang, translations, finished, unfinished, f"{int(percent):3}% {progress} |")
ignored, tsdate, int(percent), progress))
else: else:
if percent > 90: if percent > 90:
color = r'%GREEN%' color = r'%GREEN%'
@ -180,10 +180,9 @@ def langstat(pretty=True, tree=None):
else: else:
color = r'%RED%' color = r'%RED%'
print("| %s | %s | %s | %s | %s | %s | %s | %s %i%% " print(f"| {name} | {fancylang} | {translations} | {finished} "
"%%ENDCOLOR%% %s |" % f"| {unfinished} | {ignored} | {tsdate} | {color} "
(name, fancylang, translations, finished, unfinished, f"{percent:.1f}% %ENDCOLOR% {progress} |")
ignored, tsdate, color, percent, progress))
if pretty: if pretty:
print(delim) print(delim)