langstat: update for git.

Use gitscraper for retrieving files from the repository and update output a
bit. Fix some pep8 errors while at it.

Change-Id: Iff05bc916decb28bed99b83d9a32ce344d5c613b
This commit is contained in:
Dominik Riebeling 2012-04-29 11:46:25 +02:00
parent 91cf4a7768
commit 4b256de1ec

View file

@ -5,7 +5,6 @@
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
# \/ \/ \/ \/ \/ # \/ \/ \/ \/ \/
# $Id$
# #
# Copyright (c) 2010 Dominik Riebeling # Copyright (c) 2010 Dominik Riebeling
# #
@ -24,48 +23,44 @@ import subprocess
import re import re
import sys import sys
import string import string
import pysvn
import tempfile import tempfile
import os import os
import shutil import shutil
from datetime import date from datetime import date
import time import time
# extend search path for gitscraper
sys.path.append(os.path.abspath(os.path.dirname(os.path.realpath(__file__))
+ "/../../utils/common"))
import gitscraper
langs = { langs = {
'cs' : 'Czech', 'cs': 'Czech',
'de' : 'German', 'de': 'German',
'fi' : 'Finnish', 'fi': 'Finnish',
'fr' : 'French', 'fr': 'French',
'gr' : 'Greek', 'gr': 'Greek',
'he' : 'Hebrew', 'he': 'Hebrew',
'it' : 'Italian', 'it': 'Italian',
'ja' : 'Japanese', 'ja': 'Japanese',
'nl' : 'Dutch', 'nl': 'Dutch',
'pl' : 'Polish', 'pl': 'Polish',
'pt' : 'Portuguese', 'pt': 'Portuguese',
'pt_BR' : 'Portuguese (Brasileiro)', 'pt_BR': 'Portuguese (Brasileiro)',
'ru' : 'Russian', 'ru': 'Russian',
'tr' : 'Turkish', 'tr': 'Turkish',
'zh_CN' : 'Chinese', 'zh_CN': 'Chinese',
'zh_TW' : 'Chinese (trad)' 'zh_TW': 'Chinese (trad)'
} }
# modules that are not part of python itself.
try:
import pysvn
except ImportError:
print "Fatal: This script requires the pysvn package to run."
print " See http://pysvn.tigris.org/."
sys.exit(-5)
langbase = "rbutil/rbutilqt/"
svnserver = "svn://svn.rockbox.org/rockbox/trunk/"
langbase = "rbutil/rbutilqt/"
# Paths and files to retrieve from svn. # Paths and files to retrieve from svn.
# This is a mixed list, holding both paths and filenames. # This is a mixed list, holding both paths and filenames.
# Get cpp sources as well for lupdate to work. # Get cpp sources as well for lupdate to work.
svnpaths = [ langbase ] gitpaths = [langbase]
def printhelp(): def printhelp():
print "Usage:", sys.argv[0], "[options]" print "Usage:", sys.argv[0], "[options]"
@ -75,36 +70,6 @@ def printhelp():
print " --help: show this help" print " --help: show this help"
def gettrunkrev(svnsrv):
'''Get the revision of trunk for svnsrv'''
client = pysvn.Client()
entries = client.info2(svnsrv, recurse=False)
return entries[0][1].rev.number
def getsources(svnsrv, filelist, dest):
'''Get the files listed in filelist from svnsrv and put it at dest.'''
client = pysvn.Client()
print "Checking out sources from %s, please wait." % svnsrv
for elem in filelist:
url = re.subn('/$', '', svnsrv + elem)[0]
destpath = re.subn('/$', '', dest + elem)[0]
# make sure the destination path does exist
d = os.path.dirname(destpath)
if not os.path.exists(d):
os.makedirs(d)
# get from svn
try:
client.export(url, destpath)
except:
print "SVN client error: %s" % sys.exc_value
print "URL: %s, destination: %s" % (url, destpath)
return -1
print "Checkout finished."
return 0
def main(): def main():
if len(sys.argv) > 1: if len(sys.argv) > 1:
if sys.argv[1] == '--help': if sys.argv[1] == '--help':
@ -116,17 +81,22 @@ def main():
else: else:
pretty = 0 pretty = 0
# get svnpaths to temporary folder # get gitpaths to temporary folder
workfolder = tempfile.mkdtemp() + "/" workfolder = tempfile.mkdtemp() + "/"
getsources(svnserver, svnpaths, workfolder) 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,
timestamp_files=["rbutil/rbutilqt/lang"])
projectfolder = workfolder + langbase projectfolder = workfolder + langbase
# lupdate translations and drop all obsolete translations # lupdate translations and drop all obsolete translations
subprocess.Popen(["lupdate-qt4", "-no-obsolete", "rbutilqt.pro"], \ subprocess.Popen(["lupdate-qt4", "-no-obsolete", "rbutilqt.pro"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=projectfolder).communicate() stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cwd=projectfolder).communicate()
# lrelease translations to get status # lrelease translations to get status
output = subprocess.Popen(["lrelease-qt4", "rbutilqt.pro"], stdout=subprocess.PIPE, \ output = subprocess.Popen(["lrelease-qt4", "rbutilqt.pro"],
stderr=subprocess.PIPE, cwd=projectfolder).communicate() stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cwd=projectfolder).communicate()
lines = re.split(r"\n", output[0]) lines = re.split(r"\n", output[0])
re_updating = re.compile(r"^Updating.*") re_updating = re.compile(r"^Updating.*")
@ -145,38 +115,33 @@ def main():
titlemax = cur titlemax = cur
if pretty == 1: if pretty == 1:
delim = "+-" + titlemax * "-" \ spaces = [7, 5, 5, 5, 5, 27, 17]
+ "-+-------+-----+-----+-----+-----+--------------------+-----------------+" delim = "+--" + titlemax * "-"
for s in spaces:
delim += "+" + "-" * s
delim += "+"
head = "| Language" + (titlemax - 8) * " " \ head = "| Language" + (titlemax - 8) * " " \
+ " | Code |Trans| Fin |Unfin| Untr| Updated | Done |" + " | Code |Trans| Fin |Unfin| Untr| Updated | Done |"
print delim print delim
print "|" + " " * (len(head) / 2 - 3) + str(gettrunkrev(svnserver)) \ print "|" + " " * ((len(head) / 2 - len(tree) / 2) - 1) + str(tree) \
+ " " * (len(head) / 2 - 4) + "|" + " " * ((len(head) / 2 - len(tree) / 2) - 1) + "|"
print delim print delim
print head print head
print delim print delim
else: else:
print "| *Translation status as of revision " + str(gettrunkrev(svnserver)) + "* ||||||||" r = str(tree) + " (" + gitscraper.get_file_timestamp(repo, tree, ".") + ")"
print "| *Translation status as of revision " + r + "* ||||||||"
print "| *Language* | *Language Code* | *Translations* | *Finished* | " \ print "| *Language* | *Language Code* | *Translations* | *Finished* | " \
"*Unfinished* | *Untranslated* | *Updated* | *Done* |" "*Unfinished* | *Untranslated* | *Updated* | *Done* |"
client = pysvn.Client()
# scan output # scan output
i = 0 i = 0
tslateststamp = 0
tsoldeststamp = time.time()
while i < len(lines): while i < len(lines):
line = lines[i] line = lines[i]
if re_updating.search(line): if re_updating.search(line):
lang = re_qmlang.findall(line) lang = re_qmlang.findall(line)
tsfile = "lang/" + re_qmbase.findall(line)[0] + ".ts" tsfile = "rbutil/rbutilqt/lang/" + re_qmbase.findall(line)[0] + ".ts"
fileinfo = client.info2(svnserver + langbase + tsfile)[0][1] tsdate = filesprops[1][tsfile]
tsrev = fileinfo.last_changed_rev.number
tsdate = date.fromtimestamp(fileinfo.last_changed_date).isoformat()
if fileinfo.last_changed_date > tslateststamp:
tslateststamp = fileinfo.last_changed_date
if fileinfo.last_changed_date < tsoldeststamp:
tsoldeststamp = fileinfo.last_changed_date
line = lines[i + 1] line = lines[i + 1]
if re_generated.search(line): if re_generated.search(line):
@ -191,7 +156,7 @@ def main():
ignored = string.atoi(re_ignout.findall(line)[0]) ignored = string.atoi(re_ignout.findall(line)[0])
else: else:
ignored = 0 ignored = 0
if langs.has_key(lang[0]): if lang[0] in langs:
name = langs[lang[0]].strip() name = langs[lang[0]].strip()
else: else:
name = '(unknown)' name = '(unknown)'
@ -205,11 +170,10 @@ def main():
fancylang = lang[0] + " " * (5 - len(lang[0])) fancylang = lang[0] + " " * (5 - len(lang[0]))
else: else:
fancylang = lang[0] fancylang = lang[0]
tsversion = str(tsrev) + " (" + tsdate + ")" status = [fancylang, translations, finished, unfinished, ignored, tsdate, percent, bar]
status = [fancylang, translations, finished, unfinished, ignored, tsversion, percent, bar]
if pretty == 1: if pretty == 1:
thisname = name + (titlemax - len(name)) * " " thisname = name + (titlemax - len(name)) * " "
print "| " + thisname + " | %5s | %3s | %3s | %3s | %3s | %6s | %3i%% %s |" % tuple(status) print "| " + thisname + " | %5s | %3s | %3s | %3s | %3s | %25s | %3i%% %s |" % tuple(status)
else: else:
if percent > 90: if percent > 90:
color = '%%GREEN%%' color = '%%GREEN%%'
@ -226,11 +190,8 @@ def main():
if pretty == 1: if pretty == 1:
print delim print delim
print "Last language updated on " + date.fromtimestamp(tslateststamp).isoformat()
print "Oldest language update was " + date.fromtimestamp(tsoldeststamp).isoformat()
shutil.rmtree(workfolder) shutil.rmtree(workfolder)
if __name__ == "__main__": if __name__ == "__main__":
main() main()