update to use mygit

This commit is contained in:
Eric House 2014-04-30 07:25:23 -07:00
parent 6d194e5362
commit 164387b37d

View file

@ -2,6 +2,7 @@
import re, sys import re, sys
from lxml import etree from lxml import etree
import mygit, xwconfig
# Take an English strings.xml file and another, "join" them on the # Take an English strings.xml file and another, "join" them on the
@ -13,16 +14,13 @@ from lxml import etree
english = 'res/values/strings.xml' english = 'res/values/strings.xml'
other_f = 'res_src/values-%s/strings.xml' other_f = 'res_src/values-%s/strings.xml'
def readIDs(base): def readIDs(rDotJava):
ids = {} ids = {}
start = re.compile('\s*public static final class string {\s*') start = re.compile('\s*public static final class string {\s*')
end = re.compile('\s*}\s*') end = re.compile('\s*}\s*')
entry = re.compile('\s*public static final int (\S+)=(0x.*);\s*') entry = re.compile('\s*public static final int (\S+)=(0x.*);\s*')
inLine = False inLine = False
path = base + '/archive/R.java' for line in rDotJava.splitlines():
for line in open(path, 'r'):
line = line.strip()
# print line
if inLine: if inLine:
if end.match(line): if end.match(line):
break break
@ -36,11 +34,11 @@ def readIDs(base):
inLine = True inLine = True
return ids return ids
def asMap( path, ids ): def asMap( repo, rev, path, ids ):
map = {} map = {}
parser = etree.XMLParser(remove_blank_text=True) data = repo.cat( path, rev )
doc = etree.parse( path, parser ) doc = etree.fromstring( data )
for elem in doc.getroot().iter(): for elem in doc.iter():
if 'string' == elem.tag: if 'string' == elem.tag:
text = elem.text text = elem.text
if text: if text:
@ -54,20 +52,28 @@ def asMap( path, ids ):
map[id] = text map[id] = text
return map return map
def getXlationFor( base, loc ): # Build from the most recent revisions of the english and locale
ids = readIDs(base) # strings.xml files that are compatible (haven't changed since)
eng = asMap( base + '/' + english, ids ) # stringsHash on the R.java file. For now, just get what matches,
other = asMap( base + '/' + other_f % (loc), ids ) # assuming that all are updated with the same commit -- which they
# aren't.
def getXlationFor( repo, rDotJava, locale, stringsHash ):
ids = readIDs(rDotJava)
eng = asMap( repo, stringsHash, english, ids )
other = asMap( repo, stringsHash, other_f % (locale), ids )
result = [] result = []
for key in eng.keys(): for key in eng.keys():
if key in other: if key in other:
result.append( { 'id' : key, 'loc' : other[key] } ) result.append( { 'id' : key, 'loc' : other[key] } )
return result return result, stringsHash
def main(): def main():
data = getXlationFor( '.', 'ba_CK' ) repo = mygit.GitRepo( xwconfig.k_REPOPATH )
hash = '33a83b0e2fcf062f4f640ccab0785b2d2b439542'
rDotJava = repo.cat( 'R.java', hash )
data = getXlationFor( repo, rDotJava, 'ca_PS', hash )
print data print data
data = getXlationFor( '.', 'ca_PS' ) data = getXlationFor( repo, rDotJava, 'ba_CK', hash )
print data print data
############################################################################## ##############################################################################