From 3dcf833edd559509c3258f75958cc39d0d074f83 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sat, 14 Sep 2013 09:36:54 +0200 Subject: langstat: improve code style a bit. Change-Id: Ide53de01282fa49640e490a02a6e20abf4d6605a --- rbutil/rbutilqt/langstats.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'rbutil') diff --git a/rbutil/rbutilqt/langstats.py b/rbutil/rbutilqt/langstats.py index 76f47450bd..cb0bb3ffbd 100755 --- a/rbutil/rbutilqt/langstats.py +++ b/rbutil/rbutilqt/langstats.py @@ -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) -- cgit v1.2.3