How can I make string / app_name different for each taste?
I wanted to write an update, but realized that it is more than the original answer saying that I am using a Python script that corrects the source code.
The Python script has a parameter, the name of the directory. This directory contains attributes for every taste, resources such as startup icons, and a properties.txt file using the Python dictionary.
{ 'someBoolean' : True , 'someParam' : 'none' , 'appTitle' : '@string/x_app_name_xyz' }
The Python script loads the dictionary from this file and replaces the value between <string name="app_name"> and </string> the properties['appTitle'] value.
Below is the code based on as-is / as-was, etc.
for strings_xml in glob.glob("res/values*/strings.xml"): fileReplace(strings_xml,'<string name="app_name">',properties['appTitle'],'</string>',oldtextpattern=r"[a-zA-Z0-9_/@\- ]+")
to read properties from one or more of these files:
with open(filename1) as f: properties = eval(f.read()) with open(filename2) as f: properties.update(eval(f.read()))
and fileReplace function:
really = True #False for debugging # In the file 'fname', # find the text matching "before oldtext after" (all occurrences) and # replace 'oldtext' with 'newtext' (all occurrences). # If 'mandatory' is true, raise an exception if no replacements were made. def fileReplace(fname,before,newtext,after,oldtextpattern=r"[\w.]+",mandatory=True): with open(fname, 'r+') as f: read_data = f.read() pattern = r"("+re.escape(before)+r")"+oldtextpattern+"("+re.escape(after)+r")" replacement = r"\g<1>"+newtext+r"\g<2>" new_data,replacements_made = re.subn(pattern,replacement,read_data,flags=re.MULTILINE) if replacements_made and really: f.seek(0) f.truncate() f.write(new_data) if verbose: print "patching ",fname," (",replacements_made," occurrence" + ("s" if 1!=replacements_made else ""),")",newtext,("-- no changes" if new_data==read_data else "-- ***CHANGED***") elif replacements_made: print fname,":" print new_data elif mandatory: raise Exception("cannot patch the file: "+fname+" with ["+newtext+"] instead of '"+before+"{"+oldtextpattern+"}"+after+"'")
The first lines of the script:
#!/usr/bin/python