diff options
author | Stefan Rado <px4@sradonia.net> | 2014-02-15 21:24:53 +0100 |
---|---|---|
committer | Stefan Rado <px4@sradonia.net> | 2014-02-15 21:37:47 +0100 |
commit | d30335cb3f141fe0abf7ea853d5e5b097452a0a3 (patch) | |
tree | 1948898b70d3f909e26fafe395766b3b5fecc8ea /Tools/px4params/output_dokuwiki_tables.py | |
parent | 1a7518a4224082cf707585a93eb6d934127e5d9e (diff) | |
download | px4-firmware-d30335cb3f141fe0abf7ea853d5e5b097452a0a3.tar.gz px4-firmware-d30335cb3f141fe0abf7ea853d5e5b097452a0a3.tar.bz2 px4-firmware-d30335cb3f141fe0abf7ea853d5e5b097452a0a3.zip |
Fixes for Python 3 and refactoring: Merge generic Output class into specialized output classes as some need to write files in binary mode.
Diffstat (limited to 'Tools/px4params/output_dokuwiki_tables.py')
-rw-r--r-- | Tools/px4params/output_dokuwiki_tables.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Tools/px4params/output_dokuwiki_tables.py b/Tools/px4params/output_dokuwiki_tables.py new file mode 100644 index 000000000..dca3fd92d --- /dev/null +++ b/Tools/px4params/output_dokuwiki_tables.py @@ -0,0 +1,75 @@ +from xml.sax.saxutils import escape + +class DokuWikiTablesOutput(): + def __init__(self, groups): + result = "====== Parameter Reference ======\nThis list is auto-generated every few minutes and contains the most recent parameter names and default values.\n\n" + for group in groups: + result += "==== %s ====\n\n" % group.GetName() + result += "|< 100% 20% 20% 10% 10% 10% 30%>|\n" + result += "^ Name ^ Description ^ Min ^ Max ^ Default ^ Comment ^\n" + 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") + + name = name.replace("\n", " ") + result += "| %s | %s |" % (code, name) + + if min_val is not None: + result += " %s |" % min_val + else: + result += " |" + + if max_val is not None: + result += " %s |" % max_val + else: + result += " |" + + if def_val is not None: + result += " %s |" % def_val + else: + result += " |" + + if long_desc is not None: + long_desc = long_desc.replace("\n", " ") + result += " %s |" % long_desc + else: + result += " |" + + result += "\n" + result += "\n" + self.output = result; + + def Save(self, filename): + with open(filename, 'w') as f: + f.write(self.output) + + def SaveRpc(self, filename): + with open(filename, 'w') as f: + f.write("""<?xml version='1.0'?> +<methodCall> + <methodName>wiki.putPage</methodName> + <params> + <param> + <value> + <string>:firmware:parameters</string> + </value> + </param> + <param> + <value> + <string>""") + f.write(escape(self.output)) + f.write("""</string> + </value> + </param> + <param> + <value> + <name>sum</name> + <string>Updated parameters automagically from code.</string> + </value> + </param> + </params> +</methodCall>""") |