3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 # Copyright (c) 2010 Dominik Riebeling
11 # All files in this archive are subject to the GNU General Public License.
12 # See the file COPYING in the source tree root for full license agreement.
14 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 # KIND, either express or implied.
18 # lrelease all rbutil translations and create a nice table from the output
19 # suited to paste in the wiki.
29 from datetime
import date
32 # extend search path for gitscraper
33 sys
.path
.append(os
.path
.abspath(os
.path
.dirname(os
.path
.realpath(__file__
))
34 + "/../../utils/common"))
50 'pt_BR': 'Portuguese (Brasileiro)',
54 'zh_TW': 'Chinese (trad)'
58 langbase
= "rbutil/rbutilqt/"
59 # Paths and files to retrieve from svn.
60 # This is a mixed list, holding both paths and filenames.
61 # Get cpp sources as well for lupdate to work.
66 print "Usage:", sys
.argv
[0], "[options]"
67 print "Print translation statistics suitable for pasting in the wiki."
69 print " --pretty: display pretty output instead of wiki-style"
70 print " --help: show this help"
75 if sys
.argv
[1] == '--help':
79 if sys
.argv
[1] == '--pretty':
84 # get gitpaths to temporary folder
85 workfolder
= tempfile
.mkdtemp() + "/"
86 repo
= os
.path
.abspath(os
.path
.join(os
.path
.dirname(__file__
), "../.."))
87 tree
= gitscraper
.get_refs(repo
)['refs/remotes/origin/master']
88 filesprops
= gitscraper
.scrape_files(repo
, tree
, gitpaths
, dest
=workfolder
,
89 timestamp_files
=["rbutil/rbutilqt/lang"])
91 projectfolder
= workfolder
+ langbase
92 # lupdate translations and drop all obsolete translations
93 subprocess
.Popen(["lupdate-qt4", "-no-obsolete", "rbutilqt.pro"],
94 stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
,
95 cwd
=projectfolder
).communicate()
96 # lrelease translations to get status
97 output
= subprocess
.Popen(["lrelease-qt4", "rbutilqt.pro"],
98 stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
,
99 cwd
=projectfolder
).communicate()
100 lines
= re
.split(r
"\n", output
[0])
102 re_updating
= re
.compile(r
"^Updating.*")
103 re_generated
= re
.compile(r
"Generated.*")
104 re_ignored
= re
.compile(r
"Ignored.*")
105 re_qmlang
= re
.compile(r
"'.*/rbutil_(.*)\.qm'")
106 re_qmbase
= re
.compile(r
"'.*/(rbutil_.*)\.qm'")
107 re_genout
= re
.compile(r
"[^0-9]([0-9]+) .*[^0-9]([0-9]+) .*[^0-9]([0-9]+) ")
108 re_ignout
= re
.compile(r
"([0-9]+) ")
118 spaces
= [7, 5, 5, 5, 5, 27, 17]
119 delim
= "+--" + titlemax
* "-"
121 delim
+= "+" + "-" * s
123 head
= "| Language" + (titlemax
- 8) * " " \
124 + " | Code |Trans| Fin |Unfin| Untr| Updated | Done |"
126 print "|" + " " * ((len(head
) / 2 - len(tree
) / 2) - 1) + str(tree
) \
127 + " " * ((len(head
) / 2 - len(tree
) / 2) - 1) + "|"
132 r
= str(tree
) + " (" + gitscraper
.get_file_timestamp(repo
, tree
, ".") + ")"
133 print "| *Translation status as of revision " + r
+ "* ||||||||"
134 print "| *Language* | *Language Code* | *Translations* | *Finished* | " \
135 "*Unfinished* | *Untranslated* | *Updated* | *Done* |"
139 while i
< len(lines
):
141 if re_updating
.search(line
):
142 lang
= re_qmlang
.findall(line
)
143 tsfile
= "rbutil/rbutilqt/lang/" + re_qmbase
.findall(line
)[0] + ".ts"
144 tsdate
= filesprops
[1][tsfile
]
147 if re_generated
.search(line
):
148 values
= re_genout
.findall(line
)
149 translations
= string
.atoi(values
[0][0])
150 finished
= string
.atoi(values
[0][1])
151 unfinished
= string
.atoi(values
[0][2])
155 if re_ignored
.search(line
):
156 ignored
= string
.atoi(re_ignout
.findall(line
)[0])
160 name
= langs
[lang
[0]].strip()
164 percent
= (float(finished
+ unfinished
) * 100 / float(translations
+ ignored
))
165 bar
= "#" * int(percent
/ 10)
166 if (percent
% 10) > 5:
168 bar
+= " " * (10 - len(bar
))
170 fancylang
= lang
[0] + " " * (5 - len(lang
[0]))
173 status
= [fancylang
, translations
, finished
, unfinished
, ignored
, tsdate
, percent
, bar
]
175 thisname
= name
+ (titlemax
- len(name
)) * " "
176 print "| " + thisname
+ " | %5s | %3s | %3s | %3s | %3s | %25s | %3i%% %s |" % tuple(status
)
186 text
= "| " + name
+ " | %s | %s | %s | %s | %s | %s | " + color
+ "%3i%%%%ENDCOLOR%% %s |"
187 print text
% tuple(status
)
193 shutil
.rmtree(workfolder
)
196 if __name__
== "__main__":