1
0
Fork 0
forked from len0rd/rockbox

langstat: improve code style a bit.

Change-Id: Ide53de01282fa49640e490a02a6e20abf4d6605a
This commit is contained in:
Dominik Riebeling 2013-09-14 09:36:54 +02:00
parent 89afa32584
commit 3dcf833edd

View file

@ -22,7 +22,6 @@
import subprocess
import re
import sys
import string
import tempfile
import os
import shutil
@ -33,7 +32,7 @@ sys.path.append(os.path.abspath(os.path.join(
import gitscraper
langs = {
LANGS = {
'cs': 'Czech',
'de': 'German',
'fi': 'Finnish',
@ -53,11 +52,11 @@ langs = {
}
langbase = "rbutil/rbutilqt/"
LANGBASE = "rbutil/rbutilqt/"
# 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.
gitpaths = [langbase]
GITPATHS = [LANGBASE]
def printhelp():
@ -78,16 +77,19 @@ def main():
pretty = True
else:
pretty = False
langstat(pretty)
def langstat(pretty=True):
# get gitpaths to temporary folder
workfolder = tempfile.mkdtemp() + "/"
repo = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
tree = gitscraper.get_refs(repo)['refs/remotes/origin/master']
filesprops = gitscraper.scrape_files(
repo, tree, gitpaths, dest=workfolder,
repo, tree, GITPATHS, dest=workfolder,
timestamp_files=["rbutil/rbutilqt/lang"])
projectfolder = workfolder + langbase
projectfolder = workfolder + LANGBASE
# lupdate translations and drop all obsolete translations
subprocess.Popen(["lupdate-qt4", "-no-obsolete", "rbutilqt.pro"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
@ -109,16 +111,15 @@ def main():
# print header
titlemax = 0
for l in langs:
cur = len(langs[l])
for lang in LANGS:
cur = len(LANGS[lang])
if titlemax < cur:
titlemax = cur
if pretty:
spaces = [7, 5, 5, 5, 5, 27, 17]
delim = "+--" + titlemax * "-"
for s in spaces:
delim += "+" + "-" * s
for spc in [7, 5, 5, 5, 5, 27, 17]:
delim += "+" + "-" * spc
delim += "+"
head = ("| {:%s} | {:6}|{:5}|{:5}|{:5}|{:5}| {:26}| {:16}|"
% titlemax).format("Language", "Code", "Trans", "Fin", "Unfin",
@ -129,16 +130,15 @@ def main():
print(head)
print(delim)
else:
r = "%s (%s)" % (str(tree),
gitscraper.get_file_timestamp(repo, tree, "."))
print("| *Translation status as of revision %s* ||||||||" % r)
rev = "%s (%s)" % (
tree, gitscraper.get_file_timestamp(repo, tree, "."))
print("| *Translation status as of revision %s* ||||||||" % rev)
print("| *Language* | *Language Code* | *Translations* "
"| *Finished* | *Unfinished* | *Untranslated* | *Updated* "
"| *Done* |")
# scan output
i = 0
while i < len(lines):
for i in range(len(lines)):
line = lines[i]
if re_updating.search(line):
lang = re_qmlang.findall(line)
@ -158,8 +158,8 @@ def main():
ignored = int(re_ignout.findall(line)[0])
else:
ignored = 0
if lang[0] in langs:
name = langs[lang[0]].strip()
if lang[0] in LANGS:
name = LANGS[lang[0]].strip()
else:
name = '(unknown)'
@ -191,7 +191,6 @@ def main():
"%%ENDCOLOR%% %s |" %
(name, fancylang, translations, finished, unfinished,
ignored, tsdate, color, percent, bar))
i += 1
if pretty:
print(delim)