diff --git a/xwords4/android/XWords4-dbg/AndroidManifest.xml b/xwords4/android/XWords4-dbg/AndroidManifest.xml index 43170286e..9e011ae45 100644 --- a/xwords4/android/XWords4-dbg/AndroidManifest.xml +++ b/xwords4/android/XWords4-dbg/AndroidManifest.xml @@ -56,9 +56,9 @@ - - + @@ -252,7 +252,7 @@ - + diff --git a/xwords4/android/scripts/adb-uninstall.sh b/xwords4/android/scripts/adb-uninstall.sh index 9febf604e..4c5b38f37 100755 --- a/xwords4/android/scripts/adb-uninstall.sh +++ b/xwords4/android/scripts/adb-uninstall.sh @@ -3,35 +3,37 @@ set -e -u INDEX=0 +DRYRUN='' usage() { - echo "usage: $0 [--help] [-n ]" + [ $# -gt 0 ] && echo "ERROR: $1" + echo "usage: $0 [--dry-run] [--help] [-n ]" echo "uninstall crosswords from the th device" exit 0 } -if [ ! -e build.xml ]; then - usage "No build.xml; please run me from the top android directory" -fi +while :; do + WD=$(pwd) + if [ -e ${WD}/AndroidManifest.xml ]; then + break + elif [ ${WD} = '/' ]; then + usage "reached / without finding AndroidManifest.xml" + else + cd .. + fi +done -DIRNAME=$(basename $(pwd)) -case $DIRNAME in - XWords4-bt) - PKG=xw4bt - ;; - XWords4-dbg) - PKG=xw4dbg - ;; - XWords4) - PKG=xw4 - ;; - *) - usage "running in unexpected directory $DIRNAME" - ;; -esac +PACK=$(grep 'package=\".*\..*\.*\"' ${WD}/AndroidManifest.xml | sed 's,^.*package="\(.*\)".*$,\1,') + +if [ -z "${PACK}" ]; then + usage "unable to find package in ${WD}/AndroidManifest.xml" +fi while [ $# -ge 1 ]; do case $1 in + --dry-run) + DRYRUN=1 + ;; -n) shift INDEX=$1 @@ -44,4 +46,5 @@ done SERIAL="$(adb devices | grep 'device$' | sed -n "$((1+INDEX)) p" | awk '{print $1}')" -adb -s $SERIAL uninstall org.eehouse.android.${PKG} +echo "adb -s $SERIAL uninstall $PACK" +[ -z "$DRYRUN" ] && adb -s $SERIAL uninstall $PACK diff --git a/xwords4/android/scripts/check_strings.py b/xwords4/android/scripts/check_strings.py index 563b6939f..d9aa06e94 100755 --- a/xwords4/android/scripts/check_strings.py +++ b/xwords4/android/scripts/check_strings.py @@ -4,6 +4,7 @@ import re, sys, os, getopt from lxml import etree g_formats = {} +g_verbose = 0 def usage(msg=''): print @@ -20,8 +21,6 @@ def associate( formats, name, fmt ): else: forName = set() formats[name] = forName - if fmt in forName: - print "Warning: %s duplicated in %s" % (fmt, name) forName.add(fmt) # print 'added', fmt, 'to', name @@ -40,39 +39,64 @@ def checkFormats( formats ): if not foundDigit: break if curSet == testSet: - print name, "is ok" + if 0 < g_verbose: print name, "is ok" else: - print 'ERROR: sets different for', name, curSet, testSet + print 'WARNING: sets different for', name, curSet, testSet + +def checkLangFormats( engData, langData, lang ): + for key in langData: + if not key in engData: + print 'WARNING: key', key, 'in', lang, 'but not in English' + elif not engData[key] == langData[key]: + print 'ERROR: set mismatch', key, 'from', lang, engData[key], 'vs', langData[key] sys.exit(1) +def getForElem( data, pat, elem, name ): + splits = re.split( pat, elem.text ) + nParts = len(splits) + if 1 < nParts: + for ii in range(nParts): + part = splits[ii] + if re.match( pat, part ): + associate( data, name, part ) + +def getFormats( doc, pat, lang ): + result = {} + for elem in doc.findall('string'): + getForElem( result, pat, elem, elem.get('name') ) + for elem in doc.findall('plurals'): + name = elem.get('name') + for elem in elem.findall('item'): + quantity = elem.get('quantity') + if not elem.text or 0 == len(elem.text): + print 'plurals', name, 'has empty quantity', quantity, \ + 'in file', lang + sys.exit(1) + else: + getForElem( result, pat, elem, name + '/' + quantity ) + return result + def main(): if 1 < len(sys.argv): usage() + parser = etree.XMLParser(remove_blank_text=True, encoding="utf-8") wd = os.path.dirname(sys.argv[0]) - path = wd + '/../XWords4/res/values/strings.xml' # Load English - engFormats = {} - parser = etree.XMLParser(remove_blank_text=True, encoding="utf-8") + path = wd + '/../XWords4/res/values/strings.xml' doc = etree.parse(path, parser) pat = re.compile( '(%\d\$[sd])', re.DOTALL | re.MULTILINE ) - for typ in ['string', 'item']: - for elem in doc.findall(typ): - splits = re.split( pat, elem.text ) - nParts = len(splits) - if 1 < nParts: - for ii in range(nParts): - part = splits[ii] - if re.match( pat, part ): - associate( engFormats, elem.get('name'), part ) + engFormats = getFormats( doc, pat, 'en' ) checkFormats( engFormats ) + path = wd + '/../XWords4/res_src' for subdir, dirs, files in os.walk(path): for file in [file for file in files if file == "strings.xml" \ and not subdir.endswith('/values')]: - print file, subdir - - + doc = etree.parse( subdir + '/' + file, parser ) + forLang = getFormats( doc, pat, subdir ) + checkLangFormats( engFormats, forLang, subdir ) + sys.exit(0) ############################################################################## if __name__ == '__main__': diff --git a/xwords4/android/scripts/cleanvariants.sh b/xwords4/android/scripts/cleanvariants.sh index 14351deae..c18fd98bc 100755 --- a/xwords4/android/scripts/cleanvariants.sh +++ b/xwords4/android/scripts/cleanvariants.sh @@ -2,25 +2,21 @@ set -u -e -DIRS="" -VARIANT="" +DIR="" usage() { [ $# -ge 1 ] && echo "ERROR: $1" - echo "usage: $0 [--dest-dir ]*" + echo "usage: $0 [--dir ]" + echo " uses variant parent of CWD as default if not provided" exit 1 } while [ $# -ge 1 ]; do echo "\"$1\"" case $1 in - --variant-name) + --dir) shift - VARIANT=$1 - ;; - --dest-dir) - shift - DIRS="$DIRS $1" + DIR="$DIR $1" ;; *) usage "unexpected param $1" @@ -29,12 +25,26 @@ while [ $# -ge 1 ]; do shift done -for DIR in $DIRS; do - for FILE in $(find $DIR -type f); do - if git ls-files $FILE --error-unmatch 2>/dev/null; then - echo "skipping $FILE; it's under version control within this variant" +if [ -z "$DIR" ]; then + while :; do + WD=$(pwd) + if [ "/" = "$WD" ]; then + echo "reached / without finding AndroidManifest.xml" + exit 1 + elif [ -e ${WD}/AndroidManifest.xml ]; then + DIR=$WD + break else - rm $FILE + cd .. fi done +fi + +for FILE in $(find $DIR -type f); do + if git ls-files $FILE --error-unmatch 2>/dev/null; then + echo "skipping $FILE; it's under version control within this variant" + else + echo "removing $FILE" + rm $FILE + fi done