makedoku.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. import sys
  2. import xml.etree.ElementTree as ET
  3. input_list = []
  4. for arg in sys.argv[1:]:
  5. input_list.append(arg)
  6. if len(input_list) < 1:
  7. print("usage: makedoku.py <class_list.xml>")
  8. sys.exit(0)
  9. def validate_tag(elem,tag):
  10. if (elem.tag != tag):
  11. print("Tag mismatch, expected '"+tag+"', got "+elem.tag);
  12. sys.exit(255)
  13. class_names=[]
  14. classes={}
  15. def make_class_list(class_list,columns):
  16. f=open("class_list.txt","wb")
  17. prev=0
  18. col_max = len(class_list) / columns + 1
  19. print("col max is ", col_max)
  20. col_count = 0
  21. row_count = 0
  22. last_initial = ""
  23. fit_columns=[]
  24. for n in range(0,columns):
  25. fit_columns+=[[]]
  26. indexers=[]
  27. last_initial=""
  28. idx=0
  29. for n in class_list:
  30. col = idx/col_max
  31. if (col>=columns):
  32. col=columns-1
  33. fit_columns[col]+=[n]
  34. idx+=1
  35. if (n[:1]!=last_initial):
  36. indexers+=[n]
  37. last_initial=n[:1]
  38. row_max=0
  39. for n in range(0,columns):
  40. if (len(fit_columns[n])>row_max):
  41. row_max=len(fit_columns[n])
  42. for r in range(0,row_max):
  43. s="|"
  44. for c in range(0,columns):
  45. if (r>=len(fit_columns[c])):
  46. continue
  47. classname = fit_columns[c][r]
  48. initial=classname[0]
  49. if (classname in indexers):
  50. s+="**"+initial+"**|"
  51. else:
  52. s+=" |"
  53. s+="[["+classname.lower()+"|"+classname+"]]|"
  54. s+="\n"
  55. f.write(s)
  56. def dokuize_text(txt):
  57. return txt
  58. def dokuize_text(text):
  59. pos=0
  60. while(True):
  61. pos = text.find("[",pos)
  62. if (pos==-1):
  63. break
  64. endq_pos=text.find("]",pos+1)
  65. if (endq_pos==-1):
  66. break
  67. pre_text=text[:pos]
  68. post_text=text[endq_pos+1:]
  69. tag_text=text[pos+1:endq_pos]
  70. if (tag_text in class_names):
  71. tag_text="[["+tag_text.lower()+"|"+tag_text+"]]"
  72. else: #command
  73. cmd=tag_text
  74. space_pos=tag_text.find(" ")
  75. if (cmd.find("html")==0):
  76. cmd=tag_text[:space_pos]
  77. param=tag_text[space_pos+1:]
  78. tag_text="<"+param+">"
  79. elif(cmd.find("method")==0):
  80. cmd=tag_text[:space_pos]
  81. param=tag_text[space_pos+1:]
  82. if (param.find(".")!=-1):
  83. class_param,method_param=param.split(".")
  84. tag_text="[["+class_param.lower()+"#"+method_param+"|"+class_param+'.'+method_param+"]]"
  85. else:
  86. tag_text="[[#"+param+"|"+param+"]]"
  87. elif (cmd.find("image=")==0):
  88. tag_text="{{"+cmd[6:]+"}}"
  89. elif (cmd.find("url=")==0):
  90. tag_text="[["+cmd[4:]+"|"
  91. elif (cmd=="/url"):
  92. tag_text="]]>"
  93. elif (cmd=="center"):
  94. tag_text=""
  95. elif (cmd=="/center"):
  96. tag_text=""
  97. elif (cmd=="br"):
  98. tag_text="\\\\\n"
  99. elif (cmd=="i" or cmd=="/i"):
  100. tag_text="//"
  101. elif (cmd=="b" or cmd=="/b"):
  102. tag_text="**"
  103. elif (cmd=="u" or cmd=="/u"):
  104. tag_text="__"
  105. else:
  106. tag_text="["+tag_text+"]"
  107. text=pre_text+tag_text+post_text
  108. pos=len(pre_text)+len(tag_text)
  109. #tnode = ET.SubElement(parent,"div")
  110. #tnode.text=text
  111. return text
  112. def make_type(t):
  113. global class_names
  114. if (t in class_names):
  115. return "[["+t.lower()+"|"+t+"]]"
  116. return t
  117. def make_method(f,name,m,declare,event=False):
  118. s=" * "
  119. ret_type="void"
  120. args=list(m)
  121. mdata={}
  122. mdata["argidx"]=[]
  123. for a in args:
  124. if (a.tag=="return"):
  125. idx=-1
  126. elif (a.tag=="argument"):
  127. idx=int(a.attrib["index"])
  128. else:
  129. continue
  130. mdata["argidx"].append(idx)
  131. mdata[idx]=a
  132. if (not event):
  133. if (-1 in mdata["argidx"]):
  134. s+=make_type(mdata[-1].attrib["type"])
  135. else:
  136. s+="void"
  137. s+=" "
  138. if (declare):
  139. #span.attrib["class"]="funcdecl"
  140. #a=ET.SubElement(span,"a")
  141. #a.attrib["name"]=name+"_"+m.attrib["name"]
  142. #a.text=name+"::"+m.attrib["name"]
  143. s+="**"+m.attrib["name"]+"**"
  144. else:
  145. s+="[[#"+m.attrib["name"]+"|"+m.attrib["name"]+"]]"
  146. s+="**(**"
  147. argfound=False
  148. for a in mdata["argidx"]:
  149. arg=mdata[a]
  150. if (a<0):
  151. continue
  152. if (a>0):
  153. s+=", "
  154. else:
  155. s+=" "
  156. s+=make_type(arg.attrib["type"])
  157. if ("name" in arg.attrib):
  158. s+=" "+arg.attrib["name"]
  159. else:
  160. s+=" arg"+str(a)
  161. if ("default" in arg.attrib):
  162. s+="="+arg.attrib["default"]
  163. argfound=True
  164. if (argfound):
  165. s+=" "
  166. s+="**)**"
  167. if ("qualifiers" in m.attrib):
  168. s+=" "+m.attrib["qualifiers"]
  169. f.write(s+"\n")
  170. def make_doku_class(node):
  171. name = node.attrib["name"]
  172. f=open(name.lower()+".txt","wb")
  173. f.write("====== "+name+" ======\n")
  174. if ("inherits" in node.attrib):
  175. inh=node.attrib["inherits"].strip()
  176. f.write("**Inherits:** [["+inh.lower()+"|"+inh+"]]\\\\\n")
  177. if ("category" in node.attrib):
  178. f.write("**Category:** "+node.attrib["category"].strip()+"\\\\\n")
  179. briefd = node.find("brief_description")
  180. if (briefd!=None):
  181. f.write("===== Brief Description ======\n")
  182. f.write( dokuize_text(briefd.text.strip())+"\n" )
  183. methods = node.find("methods")
  184. if(methods!=None and len(list(methods))>0):
  185. f.write("===== Member Functions ======\n")
  186. for m in list(methods):
  187. make_method(f,node.attrib["name"],m,False)
  188. events = node.find("signals")
  189. if(events!=None and len(list(events))>0):
  190. f.write("===== Signals ======\n")
  191. for m in list(events):
  192. make_method(f,node.attrib["name"],m,True,True)
  193. members = node.find("members")
  194. if(members!=None and len(list(members))>0):
  195. f.write("===== Member Variables ======\n")
  196. for c in list(members):
  197. s = " * "
  198. s+=make_type(c.attrib["type"])+" "
  199. s+="**"+c.attrib["name"]+"**"
  200. if (c.text.strip()!=""):
  201. s+=" - "+c.text.strip()
  202. f.write(s+"\n")
  203. constants = node.find("constants")
  204. if(constants!=None and len(list(constants))>0):
  205. f.write("===== Numeric Constants ======\n")
  206. for c in list(constants):
  207. s = " * "
  208. s+="**"+c.attrib["name"]+"**"
  209. if ("value" in c.attrib):
  210. s+=" = **"+c.attrib["value"]+"**"
  211. if (c.text.strip()!=""):
  212. s+=" - "+c.text.strip()
  213. f.write(s+"\n")
  214. descr=node.find("description")
  215. if (descr!=None and descr.text.strip()!=""):
  216. f.write("===== Description ======\n")
  217. f.write(dokuize_text(descr.text.strip())+"\n")
  218. methods = node.find("methods")
  219. if(methods!=None and len(list(methods))>0):
  220. f.write("===== Member Function Description ======\n")
  221. for m in list(methods):
  222. d=m.find("description")
  223. if (d==None or d.text.strip()==""):
  224. continue
  225. f.write("== "+m.attrib["name"]+" ==\n")
  226. make_method(f,node.attrib["name"],m,False)
  227. f.write("\\\\\n")
  228. f.write(dokuize_text(d.text.strip()))
  229. f.write("\n")
  230. """
  231. div=ET.Element("div")
  232. div.attrib["class"]="class";
  233. a=ET.SubElement(div,"a")
  234. a.attrib["name"]=node.attrib["name"]
  235. h3=ET.SubElement(a,"h3")
  236. h3.attrib["class"]="title class_title"
  237. h3.text=node.attrib["name"]
  238. briefd = node.find("brief_description")
  239. if (briefd!=None):
  240. div2=ET.SubElement(div,"div")
  241. div2.attrib["class"]="description class_description"
  242. div2.text=briefd.text
  243. if ("inherits" in node.attrib):
  244. ET.SubElement(div,"br")
  245. div2=ET.SubElement(div,"div")
  246. div2.attrib["class"]="inheritance";
  247. span=ET.SubElement(div2,"span")
  248. span.text="Inherits: "
  249. make_type(node.attrib["inherits"],div2)
  250. if ("category" in node.attrib):
  251. ET.SubElement(div,"br")
  252. div3=ET.SubElement(div,"div")
  253. div3.attrib["class"]="category";
  254. span=ET.SubElement(div3,"span")
  255. span.attrib["class"]="category"
  256. span.text="Category: "
  257. a = ET.SubElement(div3,"a")
  258. a.attrib["class"]="category_ref"
  259. a.text=node.attrib["category"]
  260. catname=a.text
  261. if (catname.rfind("/")!=-1):
  262. catname=catname[catname.rfind("/"):]
  263. catname="CATEGORY_"+catname
  264. if (single_page):
  265. a.attrib["href"]="#"+catname
  266. else:
  267. a.attrib["href"]="category.html#"+catname
  268. methods = node.find("methods")
  269. if(methods!=None and len(list(methods))>0):
  270. h4=ET.SubElement(div,"h4")
  271. h4.text="Public Methods:"
  272. method_table=ET.SubElement(div,"table")
  273. method_table.attrib["class"]="method_list";
  274. for m in list(methods):
  275. # li = ET.SubElement(div2, "li")
  276. method_table.append( make_method_def(node.attrib["name"],m,False) )
  277. events = node.find("signals")
  278. if(events!=None and len(list(events))>0):
  279. h4=ET.SubElement(div,"h4")
  280. h4.text="Events:"
  281. event_table=ET.SubElement(div,"table")
  282. event_table.attrib["class"]="method_list";
  283. for m in list(events):
  284. # li = ET.SubElement(div2, "li")
  285. event_table.append( make_method_def(node.attrib["name"],m,False,True) )
  286. members = node.find("members")
  287. if(members!=None and len(list(members))>0):
  288. h4=ET.SubElement(div,"h4")
  289. h4.text="Public Variables:"
  290. div2=ET.SubElement(div,"div")
  291. div2.attrib["class"]="member_list";
  292. for c in list(members):
  293. li = ET.SubElement(div2, "li")
  294. div3=ET.SubElement(li,"div")
  295. div3.attrib["class"]="member";
  296. make_type(c.attrib["type"],div3)
  297. span=ET.SubElement(div3,"span")
  298. span.attrib["class"]="identifier member_name"
  299. span.text=" "+c.attrib["name"]+" "
  300. span=ET.SubElement(div3,"span")
  301. span.attrib["class"]="member_description"
  302. span.text=c.text
  303. constants = node.find("constants")
  304. if(constants!=None and len(list(constants))>0):
  305. h4=ET.SubElement(div,"h4")
  306. h4.text="Constants:"
  307. div2=ET.SubElement(div,"div")
  308. div2.attrib["class"]="constant_list";
  309. for c in list(constants):
  310. li = ET.SubElement(div2, "li")
  311. div3=ET.SubElement(li,"div")
  312. div3.attrib["class"]="constant";
  313. span=ET.SubElement(div3,"span")
  314. span.attrib["class"]="identifier constant_name"
  315. span.text=c.attrib["name"]+" "
  316. if ("value" in c.attrib):
  317. span=ET.SubElement(div3,"span")
  318. span.attrib["class"]="symbol"
  319. span.text="= "
  320. span=ET.SubElement(div3,"span")
  321. span.attrib["class"]="constant_value"
  322. span.text=c.attrib["value"]+" "
  323. span=ET.SubElement(div3,"span")
  324. span.attrib["class"]="constant_description"
  325. span.text=c.text
  326. # ET.SubElement(div,"br")
  327. descr=node.find("description")
  328. if (descr!=None and descr.text.strip()!=""):
  329. h4=ET.SubElement(div,"h4")
  330. h4.text="Description:"
  331. make_text_def(node.attrib["name"],div,descr.text)
  332. # div2=ET.SubElement(div,"div")
  333. # div2.attrib["class"]="description";
  334. # div2.text=descr.text
  335. if(methods!=None or events!=None):
  336. h4=ET.SubElement(div,"h4")
  337. h4.text="Method Documentation:"
  338. iter_list = []
  339. if (methods!=None):
  340. iter_list+=list(methods)
  341. if (events!=None):
  342. iter_list+=list(events)
  343. for m in iter_list:
  344. descr=m.find("description")
  345. if (descr==None or descr.text.strip()==""):
  346. continue;
  347. div2=ET.SubElement(div,"div")
  348. div2.attrib["class"]="method_doc";
  349. div2.append( make_method_def(node.attrib["name"],m,True) )
  350. #anchor = ET.SubElement(div2, "a")
  351. #anchor.attrib["name"] =
  352. make_text_def(node.attrib["name"],div2,descr.text)
  353. #div3=ET.SubElement(div2,"div")
  354. #div3.attrib["class"]="description";
  355. #div3.text=descr.text
  356. return div
  357. """
  358. for file in input_list:
  359. tree = ET.parse(file)
  360. doc=tree.getroot()
  361. if ("version" not in doc.attrib):
  362. print("Version missing from 'doc'")
  363. sys.exit(255)
  364. version=doc.attrib["version"]
  365. for c in list(doc):
  366. if (c.attrib["name"] in class_names):
  367. continue
  368. class_names.append(c.attrib["name"])
  369. classes[c.attrib["name"]]=c
  370. class_names.sort()
  371. make_class_list(class_names,4)
  372. for cn in class_names:
  373. c=classes[cn]
  374. make_doku_class(c)