summaryrefslogtreecommitdiff
path: root/main/misc/genFAQ.py
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2014-04-28 18:01:50 +0200
committerArne Schwabe <arne@rfc2549.org>2014-04-28 18:01:50 +0200
commit0a77bcf40724525cd5fbf51ac82093f63df4600b (patch)
treefcdd3eae81e87e0f72dc71b0b719df62b2aff445 /main/misc/genFAQ.py
parent2b31f7fc937a982f8f83c5ed9b7e2e8485c9476d (diff)
Update genFAQ script
--HG-- rename : misc/genFAQ.py => main/misc/genFAQ.py extra : rebase_source : a23e494c5276400d05ddf853af7bde77c2e52f63
Diffstat (limited to 'main/misc/genFAQ.py')
-rwxr-xr-xmain/misc/genFAQ.py118
1 files changed, 118 insertions, 0 deletions
diff --git a/main/misc/genFAQ.py b/main/misc/genFAQ.py
new file mode 100755
index 00000000..b1506420
--- /dev/null
+++ b/main/misc/genFAQ.py
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+# Quick and dirty script to generate googlecode wiki pages
+
+import codecs
+import xml.dom.minidom as dom
+import os.path
+
+faqpath = "/Users/arne/oss/ics-openvpn.wiki"
+
+header="""
+<wiki:comment>
+This page is autogenerated. Do not edit
+</wiki:comment>
+
+= Frequently aksed questions =
+"""
+
+def getString(strid,lang):
+ ostr=""
+ if strid in strres[lang]:
+ ostr=strres[lang][strid]
+ else:
+ ostr=strres["default"][strid]
+
+ ostr = ostr.replace("&lt;","<")
+ ostr = ostr.replace("&gt;",">")
+ ostr = ostr.replace("\\\"","\"")
+ ostr = ostr.replace("\\'","'")
+ ostr = ostr.replace("\\n","<p>")
+ return ostr
+
+def genPage(faqdom,lang):
+ out =""
+
+ #out+="#summary %s\n" % getString("faq_summary",lang)
+ out+= header
+
+ for xmld in faqdom.firstChild.childNodes:
+ for xmle in xmld.childNodes:
+ if xmle.nodeName == "TextView":
+ style = xmle.getAttribute("style")
+
+ textstyle = None
+ if style == "@style/faqhead":
+ textstyle = "== %s ==\n"
+ elif style == "@style/faqitem":
+ textstyle = "%s\n"
+
+ atext = xmle.getAttribute("android:text")
+ aid = xmle.getAttribute("android:id")
+ if atext:
+ atextid = atext.replace("@string/","")
+ else:
+ atextid = aid.replace("@+id/","")
+
+ out += textstyle % getString(atextid,lang)
+
+ return out
+
+
+strres={}
+
+def loadstrres(filename,lang):
+ xmlstr = dom.parse(filename)
+ strres[lang]={}
+ for xmld in xmlstr.childNodes:
+ for xmle in xmld.childNodes:
+ if xmle.nodeName == "string":
+ strname= xmle.getAttribute("name")
+ strdata = xmle.firstChild.data
+ strres[lang][strname]=strdata
+
+
+def main():
+
+ loadstrres("src/main/res/values/strings.xml","default")
+
+ faqdom = dom.parse("src/main/res/layout/faq.xml")
+ faq= genPage(faqdom,"default")
+
+ open(faqpath + "/FAQ.wiki","w").write(faq)
+
+ for directory in os.listdir("src/main/res"):
+ if directory.startswith("values-") and directory.find("-sw")==-1:
+ lang = directory.split("-",1)[1]
+ print lang
+ loadstrres("src/main/res/values-%s/strings.xml" % lang,lang)
+
+ langdir= "%s/%s" %(faqpath,lang)
+ if lang=="zh-rCN":
+ langdir= "%s/%s" %(faqpath,"zh-Hans")
+ elif lang=="zh-rTW":
+ langdir= "%s/%s" %(faqpath,"zh-Hant")
+
+
+ if not os.path.exists(langdir):
+ os.mkdir(langdir)
+
+ faq= genPage(faqdom,lang)
+ open("%s/FAQ.wiki" % langdir,"w").write(faq.encode("utf-8"))
+
+ checkFormatString(lang)
+
+def checkFormatString(lang):
+ for strid in strres["default"]:
+ ostr = getString(strid,"default")
+ tstr = getString(strid,lang)
+
+
+ for f in ["%s", "%d", "%f"] + ["%%%d$s" % d for d in range(0,10)] + ["%%%d$d" % d for d in range(0,10)]:
+ ino = ostr.find(f)==-1
+ int = tstr.find(f)==-1
+
+ if ino != int:
+ print "Mismatch",strid,f,ostr,tstr
+
+if __name__=="__main__":
+ main()