2014-04-21 06:26:43 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import sys, getopt, re
|
|
|
|
from lxml import etree
|
|
|
|
|
2014-04-24 04:35:10 +02:00
|
|
|
expr = '(' + \
|
|
|
|
'|'.join( [ \
|
|
|
|
r'%\d\$[dsXx]', \
|
|
|
|
r'\\n', \
|
|
|
|
r'\\t', \
|
|
|
|
r'\\u[\da-fA-F]{4,4}', \
|
|
|
|
r"\\'" , \
|
|
|
|
r'\\"' , \
|
2014-05-03 07:08:44 +02:00
|
|
|
r'\s' , \
|
|
|
|
r'[;:.]' , \
|
2014-04-24 04:35:10 +02:00
|
|
|
] ) + \
|
|
|
|
')'
|
|
|
|
|
|
|
|
# Can't make these work...
|
|
|
|
# r'\(' , \
|
|
|
|
# r'\)' , \
|
|
|
|
|
|
|
|
FMT = re.compile( expr, re.DOTALL )
|
2014-04-21 06:26:43 +02:00
|
|
|
|
|
|
|
def capitalize( str ):
|
|
|
|
split = re.split( FMT, str )
|
|
|
|
for ii in range(len(split)):
|
2014-04-21 06:36:41 +02:00
|
|
|
if not re.match( FMT, split[ii] ):
|
2014-04-21 06:26:43 +02:00
|
|
|
split[ii] = split[ii].upper()
|
|
|
|
result = ''.join(split)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
def reverse( str ):
|
2014-04-21 06:36:41 +02:00
|
|
|
split = re.split( FMT, str )
|
|
|
|
for ii in range(len(split)):
|
2014-05-03 07:08:44 +02:00
|
|
|
word = split[ii]
|
|
|
|
if not re.match( FMT, word ):
|
|
|
|
split[ii] = word[::-1]
|
2014-04-21 06:36:41 +02:00
|
|
|
result = ''.join(split)
|
|
|
|
return result
|
2014-04-21 06:26:43 +02:00
|
|
|
|
|
|
|
def usage():
|
|
|
|
print "usage:", sys.argv[0], '-l ca_PS|ba_CK [-o outfile]'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def main():
|
|
|
|
algo = None
|
2014-04-24 04:35:10 +02:00
|
|
|
outfile = '-'
|
2014-04-21 06:26:43 +02:00
|
|
|
try:
|
|
|
|
pairs, rest = getopt.getopt(sys.argv[1:], "l:o:")
|
|
|
|
for option, value in pairs:
|
|
|
|
if option == '-l': algo = value
|
|
|
|
elif option == '-o': outfile = value
|
|
|
|
else:
|
|
|
|
usage()
|
|
|
|
except:
|
|
|
|
print "Unexpected error:", sys.exc_info()[0]
|
|
|
|
usage()
|
|
|
|
|
|
|
|
if not algo:
|
|
|
|
print "no algo"
|
|
|
|
usage()
|
|
|
|
|
|
|
|
if algo == 'ca_PS':
|
|
|
|
func = capitalize
|
|
|
|
elif algo == 'ba_CK':
|
|
|
|
func = reverse
|
|
|
|
else:
|
2014-04-24 04:35:10 +02:00
|
|
|
print 'no func for algo', algo
|
2014-04-21 06:26:43 +02:00
|
|
|
usage()
|
|
|
|
|
|
|
|
parser = etree.XMLParser(remove_blank_text=True)
|
|
|
|
doc = etree.parse("res/values/strings.xml", parser)
|
|
|
|
for elem in doc.getroot().iter():
|
|
|
|
if 'string' == elem.tag:
|
|
|
|
text = elem.text
|
|
|
|
if text:
|
|
|
|
elem.text = func(text)
|
|
|
|
|
2014-04-24 04:35:10 +02:00
|
|
|
if '-' == outfile: out = sys.stdout
|
|
|
|
else: out = open( outfile, "w" )
|
|
|
|
out.write( etree.tostring( doc, pretty_print=True, encoding="utf-8", xml_declaration=True ) )
|
2014-04-21 06:26:43 +02:00
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|