snapshot. Should work for current case where the newest R.java is older than the app connecting

This commit is contained in:
Eric House 2014-05-01 08:15:42 -07:00
parent 7b40abfa2f
commit 8d6f46fa22

View file

@ -53,28 +53,86 @@ def asMap( repo, rev, path, ids ):
return map
# Build from the most recent revisions of the english and locale
# strings.xml files that are compatible (haven't changed since)
# strings.xml files that are compatible with (haven't changed since)
# stringsHash on the R.java file. For now, just get what matches,
# assuming that all are updated with the same commit -- which they
# aren't.
def getXlationFor( repo, rDotJava, locale, stringsHash ):
#
# The stringsHash is hard-coded for an app that's shipped (and based
# on its R.java file), but both the English and (especially) the
# non-English strings.xml files can change after. We want the newest
# of each that's still compatible with the ids compiled into the app.
# So we look for any change to R.java newer than stringsHash, and move
# backwards from one-before there to find the first (newest) version
# of the english and localized strings.xml
#
# So for R.java, we generate a list of revisions of it from HEAD back
# to the one we know. Taking the revision immediately after the one
# we know, we generate a list from it back to the one we know. The
# second revision in that list is the identifier of the newest
# strings.xml we an safely use.
#
def getXlationFor( repo, rDotJava, rDotHash, locale ):
ids = readIDs(rDotJava)
eng = asMap( repo, stringsHash, english, ids )
other = asMap( repo, stringsHash, other_f % (locale), ids )
assert rDotHash == '33a83b0e2fcf062f4f640ccab0785b2d2b439542'
############################################################
# This clusterf*ck needs to be rewritten!!!!
############################################################
# Find the hash that's sure to include the newest strings.xml files
# compatible with the R.java indicated by the app hash
head = repo.getHeadRev()
locFileName = other_f % (locale)
newerRDotJavas = repo.getRevsBetween( head, rDotHash, 'R.java' )
print 'newerRDotJavas:', newerRDotJavas
assert newerRDotJavas[len(newerRDotJavas)-1] == rDotHash
# If newerRDotJavas is of length 1, there have been no changes to
# R.java since the client shipped so we can safely use HEAD for
# locale files. Otherwise there's more work to do
if 1 == len(newerRDotJavas):
locFileRev = head
else:
newerRDot = newerRDotJavas[len(newerRDotJavas)-2]
print 'last rev before new R.java:', newerRDot
# now find the newest revision of our file prior to the change in
# R.java. Worst case we use the hash of R.java passed in
locFileRev = rDotHash
newestToRDot = repo.getRevsBetween( newerRDot, rDotHash, locFileName )
print 'newestToRDot:', newestToRDot
# If the list includes newerRDot, that's an entry we can't use.
if newestToRDot and newestToRDot[0] == newerRDot:
newestToRDot = newestToRDot[1:]
if 0 == len(newestToRDot): newestToRDot = None
if newestToRDot: locFileRev = newestToRDot[0]
print 'rev of locale string.xml:', locFileRev
eng = asMap( repo, locFileRev, english, ids )
other = asMap( repo, locFileRev, locFileName, ids )
result = []
for key in eng.keys():
if key in other:
result.append( { 'id' : key, 'loc' : other[key] } )
return result, stringsHash
return result, locFileRev
def main():
repo = mygit.GitRepo( xwconfig.k_REPOPATH )
# testing with the most recent (as of now) R.java change
hash = '33a83b0e2fcf062f4f640ccab0785b2d2b439542'
rDotJava = repo.cat( 'R.java', hash )
data = getXlationFor( repo, rDotJava, 'ca_PS', hash )
print data
data = getXlationFor( repo, rDotJava, 'ba_CK', hash )
print data
data, newHash = getXlationFor( repo, rDotJava, hash, 'ca_PS' )
print 'data for:', newHash, ':' , data
data, newHash = getXlationFor( repo, rDotJava, hash, 'ba_CK' )
print 'data for:', newHash, ':' , data
##############################################################################
if __name__ == '__main__':