diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2013-09-14 09:36:54 +0200 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2013-09-18 23:37:38 +0200 |
commit | 3dcf833edd559509c3258f75958cc39d0d074f83 (patch) | |
tree | 37ed9378ba77fa746d354423a785a80c82f48e8f | |
parent | 89afa32584f534f89f94c493f915c49dad51539d (diff) | |
download | rockbox-3dcf833edd559509c3258f75958cc39d0d074f83.tar.gz rockbox-3dcf833edd559509c3258f75958cc39d0d074f83.zip |
langstat: improve code style a bit.
Change-Id: Ide53de01282fa49640e490a02a6e20abf4d6605a
-rwxr-xr-x | rbutil/rbutilqt/langstats.py | 37 |
1 files changed, 18 insertions, 19 deletions
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 @@ | |||
22 | import subprocess | 22 | import subprocess |
23 | import re | 23 | import re |
24 | import sys | 24 | import sys |
25 | import string | ||
26 | import tempfile | 25 | import tempfile |
27 | import os | 26 | import os |
28 | import shutil | 27 | import shutil |
@@ -33,7 +32,7 @@ sys.path.append(os.path.abspath(os.path.join( | |||
33 | import gitscraper | 32 | import gitscraper |
34 | 33 | ||
35 | 34 | ||
36 | langs = { | 35 | LANGS = { |
37 | 'cs': 'Czech', | 36 | 'cs': 'Czech', |
38 | 'de': 'German', | 37 | 'de': 'German', |
39 | 'fi': 'Finnish', | 38 | 'fi': 'Finnish', |
@@ -53,11 +52,11 @@ langs = { | |||
53 | } | 52 | } |
54 | 53 | ||
55 | 54 | ||
56 | langbase = "rbutil/rbutilqt/" | 55 | LANGBASE = "rbutil/rbutilqt/" |
57 | # Paths and files to retrieve from svn. | 56 | # Paths and files to retrieve from svn. |
58 | # This is a mixed list, holding both paths and filenames. | 57 | # This is a mixed list, holding both paths and filenames. |
59 | # Get cpp sources as well for lupdate to work. | 58 | # Get cpp sources as well for lupdate to work. |
60 | gitpaths = [langbase] | 59 | GITPATHS = [LANGBASE] |
61 | 60 | ||
62 | 61 | ||
63 | def printhelp(): | 62 | def printhelp(): |
@@ -78,16 +77,19 @@ def main(): | |||
78 | pretty = True | 77 | pretty = True |
79 | else: | 78 | else: |
80 | pretty = False | 79 | pretty = False |
80 | langstat(pretty) | ||
81 | 81 | ||
82 | |||
83 | def langstat(pretty=True): | ||
82 | # get gitpaths to temporary folder | 84 | # get gitpaths to temporary folder |
83 | workfolder = tempfile.mkdtemp() + "/" | 85 | workfolder = tempfile.mkdtemp() + "/" |
84 | repo = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) | 86 | repo = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) |
85 | tree = gitscraper.get_refs(repo)['refs/remotes/origin/master'] | 87 | tree = gitscraper.get_refs(repo)['refs/remotes/origin/master'] |
86 | filesprops = gitscraper.scrape_files( | 88 | filesprops = gitscraper.scrape_files( |
87 | repo, tree, gitpaths, dest=workfolder, | 89 | repo, tree, GITPATHS, dest=workfolder, |
88 | timestamp_files=["rbutil/rbutilqt/lang"]) | 90 | timestamp_files=["rbutil/rbutilqt/lang"]) |
89 | 91 | ||
90 | projectfolder = workfolder + langbase | 92 | projectfolder = workfolder + LANGBASE |
91 | # lupdate translations and drop all obsolete translations | 93 | # lupdate translations and drop all obsolete translations |
92 | subprocess.Popen(["lupdate-qt4", "-no-obsolete", "rbutilqt.pro"], | 94 | subprocess.Popen(["lupdate-qt4", "-no-obsolete", "rbutilqt.pro"], |
93 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 95 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
@@ -109,16 +111,15 @@ def main(): | |||
109 | 111 | ||
110 | # print header | 112 | # print header |
111 | titlemax = 0 | 113 | titlemax = 0 |
112 | for l in langs: | 114 | for lang in LANGS: |
113 | cur = len(langs[l]) | 115 | cur = len(LANGS[lang]) |
114 | if titlemax < cur: | 116 | if titlemax < cur: |
115 | titlemax = cur | 117 | titlemax = cur |
116 | 118 | ||
117 | if pretty: | 119 | if pretty: |
118 | spaces = [7, 5, 5, 5, 5, 27, 17] | ||
119 | delim = "+--" + titlemax * "-" | 120 | delim = "+--" + titlemax * "-" |
120 | for s in spaces: | 121 | for spc in [7, 5, 5, 5, 5, 27, 17]: |
121 | delim += "+" + "-" * s | 122 | delim += "+" + "-" * spc |
122 | delim += "+" | 123 | delim += "+" |
123 | head = ("| {:%s} | {:6}|{:5}|{:5}|{:5}|{:5}| {:26}| {:16}|" | 124 | head = ("| {:%s} | {:6}|{:5}|{:5}|{:5}|{:5}| {:26}| {:16}|" |
124 | % titlemax).format("Language", "Code", "Trans", "Fin", "Unfin", | 125 | % titlemax).format("Language", "Code", "Trans", "Fin", "Unfin", |
@@ -129,16 +130,15 @@ def main(): | |||
129 | print(head) | 130 | print(head) |
130 | print(delim) | 131 | print(delim) |
131 | else: | 132 | else: |
132 | r = "%s (%s)" % (str(tree), | 133 | rev = "%s (%s)" % ( |
133 | gitscraper.get_file_timestamp(repo, tree, ".")) | 134 | tree, gitscraper.get_file_timestamp(repo, tree, ".")) |
134 | print("| *Translation status as of revision %s* ||||||||" % r) | 135 | print("| *Translation status as of revision %s* ||||||||" % rev) |
135 | print("| *Language* | *Language Code* | *Translations* " | 136 | print("| *Language* | *Language Code* | *Translations* " |
136 | "| *Finished* | *Unfinished* | *Untranslated* | *Updated* " | 137 | "| *Finished* | *Unfinished* | *Untranslated* | *Updated* " |
137 | "| *Done* |") | 138 | "| *Done* |") |
138 | 139 | ||
139 | # scan output | 140 | # scan output |
140 | i = 0 | 141 | for i in range(len(lines)): |
141 | while i < len(lines): | ||
142 | line = lines[i] | 142 | line = lines[i] |
143 | if re_updating.search(line): | 143 | if re_updating.search(line): |
144 | lang = re_qmlang.findall(line) | 144 | lang = re_qmlang.findall(line) |
@@ -158,8 +158,8 @@ def main(): | |||
158 | ignored = int(re_ignout.findall(line)[0]) | 158 | ignored = int(re_ignout.findall(line)[0]) |
159 | else: | 159 | else: |
160 | ignored = 0 | 160 | ignored = 0 |
161 | if lang[0] in langs: | 161 | if lang[0] in LANGS: |
162 | name = langs[lang[0]].strip() | 162 | name = LANGS[lang[0]].strip() |
163 | else: | 163 | else: |
164 | name = '(unknown)' | 164 | name = '(unknown)' |
165 | 165 | ||
@@ -191,7 +191,6 @@ def main(): | |||
191 | "%%ENDCOLOR%% %s |" % | 191 | "%%ENDCOLOR%% %s |" % |
192 | (name, fancylang, translations, finished, unfinished, | 192 | (name, fancylang, translations, finished, unfinished, |
193 | ignored, tsdate, color, percent, bar)) | 193 | ignored, tsdate, color, percent, bar)) |
194 | i += 1 | ||
195 | 194 | ||
196 | if pretty: | 195 | if pretty: |
197 | print(delim) | 196 | print(delim) |