px4-firmware/Tools/px4params/dokuwikiout.py

45 lines
1.8 KiB
Python
Raw Normal View History

from xml.sax.saxutils import escape
2014-02-15 20:47:11 -04:00
import codecs
2013-10-17 20:47:15 -03:00
class DokuWikiTablesOutput():
def __init__(self, groups):
2014-02-18 20:54:01 -04:00
result = ("====== Parameter Reference ======\n"
"<note>**This list is auto-generated from the source code** and contains the most recent parameter documentation.</note>\n"
"\n")
2013-10-17 20:47:15 -03:00
for group in groups:
result += "==== %s ====\n\n" % group.GetName()
2014-02-18 20:54:01 -04:00
result += "|< 100% 25% 45% 10% 10% 10% >|\n"
result += "^ Name ^ Description ^ Min ^ Max ^ Default ^\n"
result += "^ ::: ^ Comment ^^^^\n"
2013-10-17 20:47:15 -03:00
for param in group.GetParams():
code = param.GetFieldValue("code")
name = param.GetFieldValue("short_desc")
min_val = param.GetFieldValue("min")
max_val = param.GetFieldValue("max")
def_val = param.GetFieldValue("default")
long_desc = param.GetFieldValue("long_desc")
2014-02-18 20:54:01 -04:00
if name == code:
name = ""
2014-01-13 03:33:25 -04:00
else:
2014-02-18 20:54:01 -04:00
name = name.replace("\n", " ")
name = name.replace("|", "%%|%%")
name = name.replace("^", "%%^%%")
result += "| **%s** |" % code
result += " %s |" % name
result += " %s |" % (min_val or "")
result += " %s |" % (max_val or "")
result += " %s |" % (def_val or "")
result += "\n"
2014-01-13 03:33:25 -04:00
if long_desc is not None:
2014-02-18 20:54:01 -04:00
result += "| ::: | <div>%s</div> ||||\n" % long_desc
2014-01-13 03:33:25 -04:00
result += "\n"
self.output = result;
def Save(self, filename):
2014-02-15 20:47:11 -04:00
with codecs.open(filename, 'w', 'utf-8') as f:
f.write(self.output)