summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--scripts/README41
-rw-r--r--scripts/compare_xml.py62
-rw-r--r--scripts/language_helper.py142
-rwxr-xr-xscripts/relink-binaries.sh19
4 files changed, 264 insertions, 0 deletions
diff --git a/scripts/README b/scripts/README
new file mode 100644
index 000000000..0191d8ffa
--- /dev/null
+++ b/scripts/README
@@ -0,0 +1,41 @@
+relink-binaries.sh
+
+Intended to "relink" or change the linker path for a linked binary. Normally
+linked binaries are looking for the linker in /system/bin/linker (or
+/system/bin/linker64 for 64 bit devices). In recovery, we want to avoid
+mounting or using anything /system to allow us to install different
+ROMs or firmware. This script will run various sed commands to update the
+path to the linker to /sbin/linker64 or /sbin/linker which is sometimes
+needed especially for qseecomd (decrypt) or in some cases with user space
+touch screen binaries. Usage:
+
+./relink-binaries.sh filename
+
+The script will leave the existing file untouched and make a new file
+named filename-1-mod
+
+
+
+compare_xml.py
+
+Intended to compare two different language xml files to determine if any
+strings do not match up between the two files. Sometimes we add or rename
+or misspell string names. This script will help identify the discrepancies.
+Usage:
+
+python compare_xml.py -o target.xml
+
+
+
+language_helper.py
+
+This script reads the English and supplied other language files and
+compares the 2 and reorders and rewrites the other language to a new
+XML file such that all the strings are placed in the same order as
+the English file. It will place commented out string lines for items
+that are not present in the new file and will not include any strings
+in the new file that are no longer present in the English source.
+There is also a version tag that may be compared if present between
+the English and other language in case a translation string changes.
+
+python language_helper.py -o ../gui/theme/common/languages/es.xml
diff --git a/scripts/compare_xml.py b/scripts/compare_xml.py
new file mode 100644
index 000000000..bec41c03a
--- /dev/null
+++ b/scripts/compare_xml.py
@@ -0,0 +1,62 @@
+from xml.dom import minidom
+import sys
+import getopt
+
+HELP = """
+ compare_xml.py [ -o file.xml ]
+ -f file.xml
+ -h - help info
+"""
+
+enfile = "en.xml"
+otherfile = ""
+
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "hfo:koz", ["device="])
+except getopt.GetoptEror:
+ print HELP
+ sys.stdout.flush()
+ sys.exit(2)
+
+for opt, arg in opts:
+ if opt == "-h":
+ print HELP
+ sys.stdout.flush()
+ sys.exit()
+ elif opt == "-o":
+ otherfile = arg
+ elif opt == "-f":
+ enfile = arg
+
+if otherfile == "":
+ print HELP
+ exit()
+
+print "Comparing %s and %s" % (enfile, otherfile)
+print ""
+
+endoc = minidom.parse(enfile)
+enstrings = endoc.getElementsByTagName('string')
+
+otherdoc = minidom.parse(otherfile)
+otherstrings = otherdoc.getElementsByTagName('string')
+
+for ens in enstrings:
+ found = False
+ for others in otherstrings:
+ if ens.attributes['name'].value == others.attributes['name'].value:
+ found = True
+ break
+ if found == False:
+ print "'%s' present in %s and not in %s" % (ens.attributes['name'].value, enfile, otherfile)
+
+print ""
+
+for others in otherstrings:
+ found = False
+ for ens in enstrings:
+ if ens.attributes['name'].value == others.attributes['name'].value:
+ found = True
+ break
+ if found == False:
+ print "'%s' present in %s and not in %s" % (others.attributes['name'].value, otherfile, enfile)
diff --git a/scripts/language_helper.py b/scripts/language_helper.py
new file mode 100644
index 000000000..ae08363cc
--- /dev/null
+++ b/scripts/language_helper.py
@@ -0,0 +1,142 @@
+from xml.dom import minidom
+import sys
+import getopt
+
+# language helper
+#
+# by Ethan Yonker (Dees_Troy)
+#
+# This script reads the English and supplied other language files and
+# compares the 2 and reorders and rewrites the other language to a new
+# XML file such that all the strings are placed in the same order as
+# the English file. It will place commented out string lines for items
+# that are not present in the new file and will not include any strings
+# in the new file that are no longer present in the English source.
+# There is also a version tag that may be compared if present between
+# the English and other language in case a translation string changes.
+
+
+
+# this helps us avoid ascii unicode errors when writing the final XML
+def toprettyxml(xdoc, encoding):
+ #"""Return a pretty-printed XML document in a given encoding."""
+ unistr = xdoc.toprettyxml().replace(u'<?xml version="1.0" ?>',
+ u'<?xml version="1.0" encoding="%s"?>' % encoding)
+ return unistr.encode(encoding, 'xmlcharrefreplace')
+
+HELP = """
+ language_helper.py -o file.xml other language to compare to English
+ [ -f file.xml ] output file (defaults to new.xml)
+ -h help info
+"""
+
+enfile = "en.xml"
+otherfile = ""
+outfile = "new.xml"
+
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "hfo:koz", ["device="])
+except getopt.GetoptEror:
+ print HELP
+ sys.stdout.flush()
+ sys.exit(2)
+
+for opt, arg in opts:
+ if opt == "-h":
+ print HELP
+ sys.stdout.flush()
+ sys.exit()
+ elif opt == "-o":
+ otherfile = arg
+ elif opt == "-f":
+ outfile = arg
+
+if otherfile == "":
+ print HELP
+ exit()
+
+print "Comparing %s and %s" % (enfile, otherfile)
+print ""
+
+# Open English
+endoc = minidom.parse(enfile)
+
+# Open other language
+otherdoc = minidom.parse(otherfile)
+otherstrings = otherdoc.getElementsByTagName('string')
+
+# create minidom-document
+doc = minidom.Document()
+
+# language tag
+language = doc.createElement('language')
+doc.appendChild(language)
+
+# display tag (name of the language that shows in the GUI)
+otherlang = ""
+otherdisplay = otherdoc.getElementsByTagName('display')
+for disnode in otherdisplay:
+ if disnode.nodeType == disnode.ELEMENT_NODE:
+ language.appendChild(disnode)
+ otherlang = disnode.firstChild.data
+ print otherlang
+
+# resources
+resources = doc.createElement('resources')
+language.appendChild(resources)
+
+enres = endoc.getElementsByTagName('resources')
+for resnode in enres:
+ resc = resnode.childNodes
+ for child in resc:
+ if child.nodeType == child.ELEMENT_NODE:
+ if child.tagName != "string":
+ otherres = otherdoc.getElementsByTagName('resources')
+ found = False
+ for othernode in otherres:
+ otherresc = othernode.childNodes
+ for otherchild in otherresc:
+ if otherchild.nodeType == otherchild.ELEMENT_NODE:
+ if otherchild.tagName == child.tagName:
+ if otherchild.attributes['name'].value == child.attributes['name'].value:
+ found = True
+ resources.appendChild(otherchild)
+ break
+ if found == True:
+ break
+ if found == False:
+ print "Failed to find %s in %s, using what we got from English" % (child.toxml(), otherlang)
+ resources.appendChild(child)
+ else:
+ found = False
+ for others in otherstrings:
+ if child.attributes['name'].value == others.attributes['name'].value:
+ found = True
+ enver = "1"
+ if child.hasAttribute('version'):
+ enver = child.attributes['version'].value
+ otherver = "1"
+ if others.hasAttribute('version'):
+ otherver = others.attributes['version'].value
+ if enver != otherver:
+ ver_err = "English has version " + enver + " but " + otherlang + " has version " + otherver + " for '" + child.attributes['name'].value + "'"
+ print ver_err
+ version_comment = doc.createComment(ver_err)
+ resources.appendChild(version_comment)
+ resources.appendChild(others)
+ else:
+ resources.appendChild(others)
+ break
+ if found == False:
+ print "'%s' present in English and not in %s" % (child.attributes['name'].value, otherlang)
+ notfound_err = "NOT FOUND " + child.toxml()
+ notfound_comment = doc.createComment(notfound_err)
+ resources.appendChild(notfound_comment)
+ elif child.nodeType == child.COMMENT_NODE:
+ resources.appendChild(child)
+
+# Done, output the xml to a file
+file_handle = open(outfile,"wb")
+itspretty = toprettyxml(doc, "utf-8")
+file_handle.write(itspretty)
+file_handle.close()
diff --git a/scripts/relink-binaries.sh b/scripts/relink-binaries.sh
new file mode 100755
index 000000000..0188560e6
--- /dev/null
+++ b/scripts/relink-binaries.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+process_file()
+{
+ src=$1
+ dst=$1-1 #/$(basename $2)
+ cp -f -p $src $dst
+
+ sed "s|/system/bin/linker64\x0|/sbin/linker64\x0\x0\x0\x0\x0\x0\x0|g" $dst | sed "s|/system/bin/linker\x0|/sbin/linker\x0\x0\x0\x0\x0\x0\x0|g" | sed "s|/system/bin/sh\x0|/sbin/sh\x0\x0\x0\x0\x0\x0\x0|g" > $dst-mod
+ #sed "s|/sbin/linker\x0|/system/bin/linker\x0\x0\x0\x0\x0\x0\x0|g" $dst | sed "s|/sbin/sh\x0|/system/bin/sh\x0\x0\x0\x0\x0\x0\x0|g" > $dst-mod
+ rm $dst
+}
+
+
+dest=$1
+for ARG in $*
+do
+ process_file $dest $ARG
+done