2010-01-19 22:51:16 +00:00
|
|
|
#!/usr/bin/python
|
2010-01-19 23:01:54 +00:00
|
|
|
# __________ __ ___.
|
|
|
|
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
# \/ \/ \/ \/ \/
|
|
|
|
#
|
|
|
|
# Copyright (c) 2010 Dominik Riebeling
|
|
|
|
#
|
|
|
|
# All files in this archive are subject to the GNU General Public License.
|
|
|
|
# See the file COPYING in the source tree root for full license agreement.
|
|
|
|
#
|
|
|
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, either express or implied.
|
|
|
|
#
|
2010-01-19 22:51:16 +00:00
|
|
|
#
|
|
|
|
# lrelease all rbutil translations and create a nice table from the output
|
|
|
|
# suited to paste in the wiki.
|
|
|
|
#
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
2012-04-29 09:46:25 +00:00
|
|
|
# extend search path for gitscraper
|
2013-06-08 21:56:33 +00:00
|
|
|
sys.path.append(os.path.abspath(os.path.join(
|
|
|
|
os.path.dirname(os.path.realpath(__file__)), "../../utils/common")))
|
2012-04-29 09:46:25 +00:00
|
|
|
import gitscraper
|
|
|
|
|
2010-01-19 22:51:16 +00:00
|
|
|
|
2013-09-14 07:36:54 +00:00
|
|
|
LANGS = {
|
2012-04-29 09:46:25 +00:00
|
|
|
'cs': 'Czech',
|
|
|
|
'de': 'German',
|
|
|
|
'fi': 'Finnish',
|
|
|
|
'fr': 'French',
|
|
|
|
'gr': 'Greek',
|
|
|
|
'he': 'Hebrew',
|
|
|
|
'it': 'Italian',
|
|
|
|
'ja': 'Japanese',
|
|
|
|
'nl': 'Dutch',
|
|
|
|
'pl': 'Polish',
|
|
|
|
'pt': 'Portuguese',
|
|
|
|
'pt_BR': 'Portuguese (Brasileiro)',
|
|
|
|
'ru': 'Russian',
|
|
|
|
'tr': 'Turkish',
|
|
|
|
'zh_CN': 'Chinese',
|
|
|
|
'zh_TW': 'Chinese (trad)'
|
2010-01-19 22:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-14 07:36:54 +00:00
|
|
|
LANGBASE = "rbutil/rbutilqt/"
|
2010-01-19 22:51:16 +00:00
|
|
|
# Paths and files to retrieve from svn.
|
|
|
|
# This is a mixed list, holding both paths and filenames.
|
|
|
|
# Get cpp sources as well for lupdate to work.
|
2013-09-14 07:36:54 +00:00
|
|
|
GITPATHS = [LANGBASE]
|
2012-04-29 09:46:25 +00:00
|
|
|
|
2010-01-19 22:51:16 +00:00
|
|
|
|
|
|
|
def printhelp():
|
2013-06-08 21:56:33 +00:00
|
|
|
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")
|
2010-01-19 22:51:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
if sys.argv[1] == '--help':
|
|
|
|
printhelp()
|
|
|
|
sys.exit(0)
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
if sys.argv[1] == '--pretty':
|
2013-06-08 21:56:33 +00:00
|
|
|
pretty = True
|
2010-01-19 22:51:16 +00:00
|
|
|
else:
|
2013-06-08 21:56:33 +00:00
|
|
|
pretty = False
|
2013-09-14 07:36:54 +00:00
|
|
|
langstat(pretty)
|
2010-01-19 22:51:16 +00:00
|
|
|
|
2013-09-14 07:36:54 +00:00
|
|
|
|
|
|
|
def langstat(pretty=True):
|
2012-04-29 09:46:25 +00:00
|
|
|
# get gitpaths to temporary folder
|
2010-01-19 22:51:16 +00:00
|
|
|
workfolder = tempfile.mkdtemp() + "/"
|
2012-04-29 09:46:25 +00:00
|
|
|
repo = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
|
|
|
|
tree = gitscraper.get_refs(repo)['refs/remotes/origin/master']
|
2013-06-08 21:56:33 +00:00
|
|
|
filesprops = gitscraper.scrape_files(
|
2013-09-14 07:36:54 +00:00
|
|
|
repo, tree, GITPATHS, dest=workfolder,
|
2013-06-08 21:56:33 +00:00
|
|
|
timestamp_files=["rbutil/rbutilqt/lang"])
|
2010-01-19 22:51:16 +00:00
|
|
|
|
2013-09-14 07:36:54 +00:00
|
|
|
projectfolder = workfolder + LANGBASE
|
2010-01-19 22:51:16 +00:00
|
|
|
# lupdate translations and drop all obsolete translations
|
2012-04-29 09:46:25 +00:00
|
|
|
subprocess.Popen(["lupdate-qt4", "-no-obsolete", "rbutilqt.pro"],
|
2013-06-08 21:56:33 +00:00
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
|
|
cwd=projectfolder).communicate()
|
2010-01-19 22:51:16 +00:00
|
|
|
# lrelease translations to get status
|
2012-04-29 09:46:25 +00:00
|
|
|
output = subprocess.Popen(["lrelease-qt4", "rbutilqt.pro"],
|
2013-06-08 21:56:33 +00:00
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
|
|
cwd=projectfolder).communicate()
|
|
|
|
lines = re.split(r"\n", output[0].decode())
|
2010-01-19 22:51:16 +00:00
|
|
|
|
|
|
|
re_updating = re.compile(r"^Updating.*")
|
|
|
|
re_generated = re.compile(r"Generated.*")
|
|
|
|
re_ignored = re.compile(r"Ignored.*")
|
|
|
|
re_qmlang = re.compile(r"'.*/rbutil_(.*)\.qm'")
|
|
|
|
re_qmbase = re.compile(r"'.*/(rbutil_.*)\.qm'")
|
2013-06-08 21:56:33 +00:00
|
|
|
re_genout = re.compile(
|
|
|
|
r"[^0-9]([0-9]+) .*[^0-9]([0-9]+) .*[^0-9]([0-9]+) ")
|
2010-01-19 22:51:16 +00:00
|
|
|
re_ignout = re.compile(r"([0-9]+) ")
|
|
|
|
|
|
|
|
# print header
|
|
|
|
titlemax = 0
|
2013-09-14 07:36:54 +00:00
|
|
|
for lang in LANGS:
|
|
|
|
cur = len(LANGS[lang])
|
2010-01-19 22:51:16 +00:00
|
|
|
if titlemax < cur:
|
|
|
|
titlemax = cur
|
|
|
|
|
2013-06-08 21:56:33 +00:00
|
|
|
if pretty:
|
2012-04-29 09:46:25 +00:00
|
|
|
delim = "+--" + titlemax * "-"
|
2013-09-14 07:36:54 +00:00
|
|
|
for spc in [7, 5, 5, 5, 5, 27, 17]:
|
|
|
|
delim += "+" + "-" * spc
|
2012-04-29 09:46:25 +00:00
|
|
|
delim += "+"
|
2013-06-08 21:56:33 +00:00
|
|
|
head = ("| {:%s} | {:6}|{:5}|{:5}|{:5}|{:5}| {:26}| {:16}|"
|
|
|
|
% titlemax).format("Language", "Code", "Trans", "Fin", "Unfin",
|
|
|
|
"Untr", "Updated", "Done")
|
|
|
|
print(delim)
|
|
|
|
print(("| {:^%s} |" % (len(head) - 4)).format(tree))
|
|
|
|
print(delim)
|
|
|
|
print(head)
|
|
|
|
print(delim)
|
2010-01-19 22:51:16 +00:00
|
|
|
else:
|
2013-09-14 07:36:54 +00:00
|
|
|
rev = "%s (%s)" % (
|
|
|
|
tree, gitscraper.get_file_timestamp(repo, tree, "."))
|
|
|
|
print("| *Translation status as of revision %s* ||||||||" % rev)
|
2013-06-08 21:56:33 +00:00
|
|
|
print("| *Language* | *Language Code* | *Translations* "
|
|
|
|
"| *Finished* | *Unfinished* | *Untranslated* | *Updated* "
|
|
|
|
"| *Done* |")
|
2010-01-19 22:51:16 +00:00
|
|
|
|
|
|
|
# scan output
|
2013-09-14 07:36:54 +00:00
|
|
|
for i in range(len(lines)):
|
2010-01-19 22:51:16 +00:00
|
|
|
line = lines[i]
|
|
|
|
if re_updating.search(line):
|
|
|
|
lang = re_qmlang.findall(line)
|
2013-06-08 21:56:33 +00:00
|
|
|
tsfile = "rbutil/rbutilqt/lang/%s.ts" % re_qmbase.findall(line)[0]
|
2012-04-29 09:46:25 +00:00
|
|
|
tsdate = filesprops[1][tsfile]
|
2010-01-19 22:51:16 +00:00
|
|
|
|
|
|
|
line = lines[i + 1]
|
|
|
|
if re_generated.search(line):
|
|
|
|
values = re_genout.findall(line)
|
2013-06-08 21:56:33 +00:00
|
|
|
translations = int(values[0][0])
|
|
|
|
finished = int(values[0][1])
|
|
|
|
unfinished = int(values[0][2])
|
2010-01-19 22:51:16 +00:00
|
|
|
line = lines[i + 2]
|
|
|
|
if not line.strip():
|
|
|
|
line = lines[i + 3]
|
|
|
|
if re_ignored.search(line):
|
2013-06-08 21:56:33 +00:00
|
|
|
ignored = int(re_ignout.findall(line)[0])
|
2010-01-19 22:51:16 +00:00
|
|
|
else:
|
|
|
|
ignored = 0
|
2013-09-14 07:36:54 +00:00
|
|
|
if lang[0] in LANGS:
|
|
|
|
name = LANGS[lang[0]].strip()
|
2010-01-19 22:51:16 +00:00
|
|
|
else:
|
|
|
|
name = '(unknown)'
|
|
|
|
|
2013-06-08 21:56:33 +00:00
|
|
|
percent = (finished + unfinished) * 100. / (translations + ignored)
|
2010-01-19 22:51:16 +00:00
|
|
|
bar = "#" * int(percent / 10)
|
|
|
|
if (percent % 10) > 5:
|
|
|
|
bar += "+"
|
|
|
|
bar += " " * (10 - len(bar))
|
2013-06-08 21:56:33 +00:00
|
|
|
if pretty:
|
2010-01-19 22:51:16 +00:00
|
|
|
fancylang = lang[0] + " " * (5 - len(lang[0]))
|
|
|
|
else:
|
|
|
|
fancylang = lang[0]
|
2013-06-08 21:56:33 +00:00
|
|
|
if pretty:
|
|
|
|
print(("| {:%i} | {:5} | {:3} | {:3} | {:3} | {:3} | {:25} | "
|
|
|
|
"{:3}%% {} |"
|
|
|
|
% titlemax).format(
|
|
|
|
name, fancylang, translations, finished, unfinished,
|
|
|
|
ignored, tsdate, int(percent), bar))
|
2010-01-19 22:51:16 +00:00
|
|
|
else:
|
|
|
|
if percent > 90:
|
2013-06-08 21:56:33 +00:00
|
|
|
color = r'%GREEN%'
|
2010-01-19 22:51:16 +00:00
|
|
|
else:
|
|
|
|
if percent > 50:
|
2013-06-08 21:56:33 +00:00
|
|
|
color = r'%ORANGE%'
|
2010-01-19 22:51:16 +00:00
|
|
|
else:
|
2013-06-08 21:56:33 +00:00
|
|
|
color = r'%RED%'
|
2010-01-19 22:51:16 +00:00
|
|
|
|
2013-06-08 21:56:33 +00:00
|
|
|
print("| %s | %s | %s | %s | %s | %s | %s | %s %i%% "
|
|
|
|
"%%ENDCOLOR%% %s |" %
|
|
|
|
(name, fancylang, translations, finished, unfinished,
|
|
|
|
ignored, tsdate, color, percent, bar))
|
2010-01-19 22:51:16 +00:00
|
|
|
|
2013-06-08 21:56:33 +00:00
|
|
|
if pretty:
|
|
|
|
print(delim)
|
2010-01-19 22:51:16 +00:00
|
|
|
|
|
|
|
shutil.rmtree(workfolder)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|