mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +01:00
changes necessary to actually return a translation based on revision
hash of R.java passed by client, or none if it already has it. Rough, but works.
This commit is contained in:
parent
56a057f06c
commit
ad65b93ef2
2 changed files with 68 additions and 64 deletions
|
@ -2,7 +2,8 @@
|
||||||
# Script meant to be installed on eehouse.org.
|
# Script meant to be installed on eehouse.org.
|
||||||
|
|
||||||
import logging, shelve, hashlib, sys, json, subprocess, glob, os
|
import logging, shelve, hashlib, sys, json, subprocess, glob, os
|
||||||
import mk_for_download
|
import mk_for_download, mygit
|
||||||
|
import xwconfig
|
||||||
|
|
||||||
from stat import ST_CTIME
|
from stat import ST_CTIME
|
||||||
try:
|
try:
|
||||||
|
@ -12,6 +13,7 @@ except ImportError:
|
||||||
apacheAvailable = False
|
apacheAvailable = False
|
||||||
|
|
||||||
# constants that are also used in UpdateCheckReceiver.java
|
# constants that are also used in UpdateCheckReceiver.java
|
||||||
|
VERBOSE = False
|
||||||
k_NAME = 'name'
|
k_NAME = 'name'
|
||||||
k_AVERS = 'avers'
|
k_AVERS = 'avers'
|
||||||
k_GVERS = 'gvers'
|
k_GVERS = 'gvers'
|
||||||
|
@ -24,6 +26,8 @@ k_CALLBACK = 'callback'
|
||||||
k_LOCALE = 'locale'
|
k_LOCALE = 'locale'
|
||||||
k_XLATPROTO = 'proto'
|
k_XLATPROTO = 'proto'
|
||||||
k_XLATEVERS = 'xlatevers'
|
k_XLATEVERS = 'xlatevers'
|
||||||
|
k_STRINGSHASH = 'strings'
|
||||||
|
|
||||||
k_OLD = 'old'
|
k_OLD = 'old'
|
||||||
k_NEW = 'new'
|
k_NEW = 'new'
|
||||||
k_PAIRS = 'pairs'
|
k_PAIRS = 'pairs'
|
||||||
|
@ -133,7 +137,7 @@ def getOrderedApks( path ):
|
||||||
|
|
||||||
files = ((os.stat(apk).st_mtime, apk) for apk in glob.glob(pattern))
|
files = ((os.stat(apk).st_mtime, apk) for apk in glob.glob(pattern))
|
||||||
for mtime, file in sorted(files, reverse=True):
|
for mtime, file in sorted(files, reverse=True):
|
||||||
logging.debug( file + ": " + str(mtime) )
|
# logging.debug( file + ": " + str(mtime) )
|
||||||
apks.append( file )
|
apks.append( file )
|
||||||
|
|
||||||
return apks
|
return apks
|
||||||
|
@ -178,11 +182,11 @@ def dictVersion( req, name, lang, md5sum ):
|
||||||
if 'close' in s_shelf: s_shelf.close()
|
if 'close' in s_shelf: s_shelf.close()
|
||||||
return json.dumps( result )
|
return json.dumps( result )
|
||||||
|
|
||||||
def getApp( params ):
|
def getApp( params, name ):
|
||||||
result = None
|
result = None
|
||||||
if k_NAME in params:
|
if k_NAME in params:
|
||||||
name = params[k_NAME]
|
name = params[k_NAME]
|
||||||
|
if name:
|
||||||
# If we're a dev device, always push the latest
|
# If we're a dev device, always push the latest
|
||||||
if k_DEVOK in params and params[k_DEVOK]:
|
if k_DEVOK in params and params[k_DEVOK]:
|
||||||
apks = getOrderedApks( k_filebase + k_apkDir )
|
apks = getOrderedApks( k_filebase + k_apkDir )
|
||||||
|
@ -246,19 +250,56 @@ def getDicts( params ):
|
||||||
if 0 == len(result): result = None
|
if 0 == len(result): result = None
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def getXlate( params ):
|
def variantFor( name ):
|
||||||
result = []
|
if name == 'xw4': result = 'XWords4'
|
||||||
logging.debug( "getXlate:" + json.dumps(params) )
|
logging.debug( 'variantFor(%s)=>%s' % (name, result))
|
||||||
for entry in params:
|
return result
|
||||||
locale = entry[k_LOCALE]
|
|
||||||
curVers = entry[k_XLATEVERS]
|
|
||||||
|
|
||||||
data = mk_for_download.getXlationFor( k_filebase + 'xw4', locale )
|
def getXlate( params, name, stringsHash ):
|
||||||
if data: result.append( { k_LOCALE: locale,
|
result = []
|
||||||
k_OLD: curVers,
|
path = xwconfig.k_REPOPATH
|
||||||
k_NEW: curVers + "_new",
|
logging.debug('creating repo with path ' + path)
|
||||||
k_PAIRS: data,
|
repo = mygit.GitRepo( path )
|
||||||
} )
|
logging.debug( "getXlate: %s, hash=%s" % (json.dumps(params), stringsHash) )
|
||||||
|
# logging.debug( 'status: ' + repo.status() )
|
||||||
|
|
||||||
|
# reduce org.eehouse.anroid.xxx to xxx, then turn it into a
|
||||||
|
# variant and get the contents of the R.java file
|
||||||
|
splits = name.split('.')
|
||||||
|
name = splits[len(splits)-1]
|
||||||
|
variant = variantFor( name );
|
||||||
|
rPath = '%s/archive/R.java' % variant
|
||||||
|
rDotJava = repo.cat( rPath, stringsHash )
|
||||||
|
|
||||||
|
# Figure out the newest hash possible for translated strings.xml
|
||||||
|
# files. If our R.java's the newest, that's HEAD. Otherwise it's
|
||||||
|
# the revision BEFORE the revision that changed R.java
|
||||||
|
|
||||||
|
head = repo.getHeadRev()
|
||||||
|
logging.debug('head = %s' % head)
|
||||||
|
rjavarevs = repo.getRevsBetween(head, stringsHash, rPath)
|
||||||
|
assert( 1 >= len(rjavarevs) )
|
||||||
|
assert( stringsHash == rjavarevs[len(rjavarevs)-1] )
|
||||||
|
if 1 == len(rjavarevs):
|
||||||
|
firstPossible = head
|
||||||
|
else:
|
||||||
|
firstPossible = rjavarevs[len(rjavarevs)-2] + '^'
|
||||||
|
# get actual number for rev^
|
||||||
|
firstPossible = repo.getRevsBetween( firstPossible, firstPossible )[0]
|
||||||
|
logging.debug('firstPossible: %s' % firstPossible)
|
||||||
|
|
||||||
|
for entry in params:
|
||||||
|
curVers = entry[k_XLATEVERS]
|
||||||
|
if not curVers == firstPossible:
|
||||||
|
locale = entry[k_LOCALE]
|
||||||
|
|
||||||
|
data = mk_for_download.getXlationFor( repo, rDotJava, locale, \
|
||||||
|
firstPossible )
|
||||||
|
if data: result.append( { k_LOCALE: locale,
|
||||||
|
k_OLD: curVers,
|
||||||
|
k_NEW: firstPossible,
|
||||||
|
k_PAIRS: data,
|
||||||
|
} )
|
||||||
|
|
||||||
if 0 == len(result): result = None
|
if 0 == len(result): result = None
|
||||||
logging.debug( "getXlate=>%s" % (json.dumps(result)) )
|
logging.debug( "getXlate=>%s" % (json.dumps(result)) )
|
||||||
|
@ -270,16 +311,17 @@ def getUpdates( req, params ):
|
||||||
logging.debug( "getUpdates: got params: %s" % params )
|
logging.debug( "getUpdates: got params: %s" % params )
|
||||||
asJson = json.loads( params )
|
asJson = json.loads( params )
|
||||||
if k_APP in asJson:
|
if k_APP in asJson:
|
||||||
appResult = getApp( asJson[k_APP] )
|
name = None
|
||||||
|
if k_NAME in asJson: name = asJson[k_NAME]
|
||||||
|
appResult = getApp( asJson[k_APP], name )
|
||||||
if appResult:
|
if appResult:
|
||||||
result[k_APP] = appResult
|
result[k_APP] = appResult
|
||||||
if k_DICTS in asJson:
|
if k_DICTS in asJson:
|
||||||
dictsResult = getDicts( asJson[k_DICTS] )
|
dictsResult = getDicts( asJson[k_DICTS] )
|
||||||
if dictsResult:
|
if dictsResult:
|
||||||
result[k_DICTS] = dictsResult
|
result[k_DICTS] = dictsResult
|
||||||
if k_XLATEINFO in asJson:
|
if k_XLATEINFO in asJson and k_NAME in asJson and k_STRINGSHASH in asJson:
|
||||||
logging.debug( "found xlate info; calling getXlate" )
|
xlateResult = getXlate( asJson[k_XLATEINFO], asJson[k_NAME], asJson[k_STRINGSHASH] )
|
||||||
xlateResult = getXlate( asJson[k_XLATEINFO] )
|
|
||||||
if xlateResult:
|
if xlateResult:
|
||||||
logging.debug( xlateResult )
|
logging.debug( xlateResult )
|
||||||
result[k_XLATEINFO] = xlateResult;
|
result[k_XLATEINFO] = xlateResult;
|
||||||
|
|
|
@ -72,55 +72,17 @@ def asMap( repo, rev, path, ids ):
|
||||||
# second revision in that list is the identifier of the newest
|
# second revision in that list is the identifier of the newest
|
||||||
# strings.xml we an safely use.
|
# strings.xml we an safely use.
|
||||||
#
|
#
|
||||||
def getXlationFor( repo, rDotJava, rDotHash, locale ):
|
def getXlationFor( repo, rDotJava, locale, firstHash ):
|
||||||
ids = readIDs(rDotJava)
|
ids = readIDs(rDotJava)
|
||||||
|
|
||||||
assert rDotHash == '33a83b0e2fcf062f4f640ccab0785b2d2b439542'
|
eng = asMap( repo, firstHash, english, ids )
|
||||||
|
|
||||||
############################################################
|
|
||||||
# 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)
|
locFileName = other_f % (locale)
|
||||||
newerRDotJavas = repo.getRevsBetween( head, rDotHash, 'R.java' )
|
other = asMap( repo, firstHash, locFileName, ids )
|
||||||
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 = []
|
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, locFileRev
|
return result
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
repo = mygit.GitRepo( xwconfig.k_REPOPATH )
|
repo = mygit.GitRepo( xwconfig.k_REPOPATH )
|
||||||
|
@ -129,9 +91,9 @@ def main():
|
||||||
hash = '33a83b0e2fcf062f4f640ccab0785b2d2b439542'
|
hash = '33a83b0e2fcf062f4f640ccab0785b2d2b439542'
|
||||||
|
|
||||||
rDotJava = repo.cat( 'R.java', hash )
|
rDotJava = repo.cat( 'R.java', hash )
|
||||||
data, newHash = getXlationFor( repo, rDotJava, hash, 'ca_PS' )
|
data, newHash = getXlationFor( repo, rDotJava, 'ca_PS', hash )
|
||||||
print 'data for:', newHash, ':' , data
|
print 'data for:', newHash, ':' , data
|
||||||
data, newHash = getXlationFor( repo, rDotJava, hash, 'ba_CK' )
|
data, newHash = getXlationFor( repo, rDotJava, 'ba_CK', hash )
|
||||||
print 'data for:', newHash, ':' , data
|
print 'data for:', newHash, ':' , data
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
Loading…
Reference in a new issue