From d30335cb3f141fe0abf7ea853d5e5b097452a0a3 Mon Sep 17 00:00:00 2001 From: Stefan Rado Date: Sat, 15 Feb 2014 21:24:53 +0100 Subject: Fixes for Python 3 and refactoring: Merge generic Output class into specialized output classes as some need to write files in binary mode. --- Tools/px4params/.gitignore | 1 + Tools/px4params/dokuwikiout.py | 68 -------------------------- Tools/px4params/dokuwikiout_listings.py | 27 ----------- Tools/px4params/output.py | 5 -- Tools/px4params/output_dokuwiki_listings.py | 30 ++++++++++++ Tools/px4params/output_dokuwiki_tables.py | 75 +++++++++++++++++++++++++++++ Tools/px4params/output_xml.py | 25 ++++++++++ Tools/px4params/px_process_params.py | 22 ++++++--- Tools/px4params/xmlout.py | 22 --------- Tools/px4params/xmlrpc.sh | 2 +- 10 files changed, 146 insertions(+), 131 deletions(-) delete mode 100644 Tools/px4params/dokuwikiout.py delete mode 100644 Tools/px4params/dokuwikiout_listings.py delete mode 100644 Tools/px4params/output.py create mode 100644 Tools/px4params/output_dokuwiki_listings.py create mode 100644 Tools/px4params/output_dokuwiki_tables.py create mode 100644 Tools/px4params/output_xml.py delete mode 100644 Tools/px4params/xmlout.py (limited to 'Tools/px4params') diff --git a/Tools/px4params/.gitignore b/Tools/px4params/.gitignore index 5d0378b4a..d78b71a6e 100644 --- a/Tools/px4params/.gitignore +++ b/Tools/px4params/.gitignore @@ -1,3 +1,4 @@ parameters.wiki parameters.xml +parameters.wikirpc.xml cookies.txt \ No newline at end of file diff --git a/Tools/px4params/dokuwikiout.py b/Tools/px4params/dokuwikiout.py deleted file mode 100644 index e02035423..000000000 --- a/Tools/px4params/dokuwikiout.py +++ /dev/null @@ -1,68 +0,0 @@ -import output -from xml.sax.saxutils import escape - -class DokuWikiOutput(output.Output): - def Generate(self, groups): - pre_text = """ - - wiki.putPage - - - - :firmware:parameters - - - - - """ - result = "====== Parameter Reference ======\nThis list is auto-generated every few minutes and contains the most recent parameter names and default values." - 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" - post_text = """ - - - - - sum - Updated parameters automagically from code. - - - - """ - return pre_text + escape(result) + post_text diff --git a/Tools/px4params/dokuwikiout_listings.py b/Tools/px4params/dokuwikiout_listings.py deleted file mode 100644 index 33f76b415..000000000 --- a/Tools/px4params/dokuwikiout_listings.py +++ /dev/null @@ -1,27 +0,0 @@ -import output - -class DokuWikiOutput(output.Output): - def Generate(self, groups): - result = "" - for group in groups: - result += "==== %s ====\n\n" % group.GetName() - for param in group.GetParams(): - code = param.GetFieldValue("code") - name = param.GetFieldValue("short_desc") - if code != name: - name = "%s (%s)" % (name, code) - result += "=== %s ===\n\n" % name - long_desc = param.GetFieldValue("long_desc") - if long_desc is not None: - result += "%s\n\n" % long_desc - min_val = param.GetFieldValue("min") - if min_val is not None: - result += "* Minimal value: %s\n" % min_val - max_val = param.GetFieldValue("max") - if max_val is not None: - result += "* Maximal value: %s\n" % max_val - def_val = param.GetFieldValue("default") - if def_val is not None: - result += "* Default value: %s\n" % def_val - result += "\n" - return result diff --git a/Tools/px4params/output.py b/Tools/px4params/output.py deleted file mode 100644 index c09246871..000000000 --- a/Tools/px4params/output.py +++ /dev/null @@ -1,5 +0,0 @@ -class Output(object): - def Save(self, groups, fn): - data = self.Generate(groups) - with open(fn, 'w') as f: - f.write(data) diff --git a/Tools/px4params/output_dokuwiki_listings.py b/Tools/px4params/output_dokuwiki_listings.py new file mode 100644 index 000000000..117f4edf4 --- /dev/null +++ b/Tools/px4params/output_dokuwiki_listings.py @@ -0,0 +1,30 @@ + +class DokuWikiListingsOutput(): + def __init__(self, groups): + result = "" + for group in groups: + result += "==== %s ====\n\n" % group.GetName() + for param in group.GetParams(): + code = param.GetFieldValue("code") + name = param.GetFieldValue("short_desc") + if code != name: + name = "%s (%s)" % (name, code) + result += "=== %s ===\n\n" % name + long_desc = param.GetFieldValue("long_desc") + if long_desc is not None: + result += "%s\n\n" % long_desc + min_val = param.GetFieldValue("min") + if min_val is not None: + result += "* Minimal value: %s\n" % min_val + max_val = param.GetFieldValue("max") + if max_val is not None: + result += "* Maximal value: %s\n" % max_val + def_val = param.GetFieldValue("default") + if def_val is not None: + result += "* Default value: %s\n" % def_val + result += "\n" + self.output = result + + def Save(self, filename): + with open(filename, 'w') as f: + f.write(self.output) 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(""" + + wiki.putPage + + + + :firmware:parameters + + + + + """) + f.write(escape(self.output)) + f.write(""" + + + + + sum + Updated parameters automagically from code. + + + +""") diff --git a/Tools/px4params/output_xml.py b/Tools/px4params/output_xml.py new file mode 100644 index 000000000..5576954c0 --- /dev/null +++ b/Tools/px4params/output_xml.py @@ -0,0 +1,25 @@ +from xml.dom.minidom import getDOMImplementation + +class XMLOutput(): + def __init__(self, groups): + impl = getDOMImplementation() + xml_document = impl.createDocument(None, "parameters", None) + xml_parameters = xml_document.documentElement + for group in groups: + xml_group = xml_document.createElement("group") + xml_group.setAttribute("name", group.GetName()) + xml_parameters.appendChild(xml_group) + for param in group.GetParams(): + xml_param = xml_document.createElement("parameter") + xml_group.appendChild(xml_param) + for code in param.GetFieldCodes(): + value = param.GetFieldValue(code) + xml_field = xml_document.createElement(code) + xml_param.appendChild(xml_field) + xml_value = xml_document.createTextNode(value) + xml_field.appendChild(xml_value) + self.output = xml_document.toprettyxml(indent=" ", newl="\n", encoding="utf-8") + + def Save(self, filename): + with open(filename, 'wb') as f: + f.write(self.output) diff --git a/Tools/px4params/px_process_params.py b/Tools/px4params/px_process_params.py index 4f498026f..7799f6348 100755 --- a/Tools/px4params/px_process_params.py +++ b/Tools/px4params/px_process_params.py @@ -41,8 +41,9 @@ import scanner import srcparser -import xmlout -import dokuwikiout +import output_xml +import output_dokuwiki_tables +import output_dokuwiki_listings # Initialize parser prs = srcparser.Parser() @@ -50,12 +51,17 @@ prs = srcparser.Parser() # Scan directories, and parse the files sc = scanner.Scanner() sc.ScanDir("../../src", prs) -output = prs.GetParamGroups() +groups = prs.GetParamGroups() # Output into XML -out = xmlout.XMLOutput() -out.Save(output, "parameters.xml") +out = output_xml.XMLOutput(groups) +out.Save("parameters.xml") -# Output into DokuWiki -out = dokuwikiout.DokuWikiOutput() -out.Save(output, "parameters.wiki") +# Output to DokuWiki listings +#out = output_dokuwiki_listings.DokuWikiListingsOutput(groups) +#out.Save("parameters.wiki") + +# Output to DokuWiki tables +out = output_dokuwiki_tables.DokuWikiTablesOutput(groups) +out.Save("parameters.wiki") +out.SaveRpc("parameters.wikirpc.xml") diff --git a/Tools/px4params/xmlout.py b/Tools/px4params/xmlout.py deleted file mode 100644 index d56802b15..000000000 --- a/Tools/px4params/xmlout.py +++ /dev/null @@ -1,22 +0,0 @@ -import output -from xml.dom.minidom import getDOMImplementation - -class XMLOutput(output.Output): - def Generate(self, groups): - impl = getDOMImplementation() - xml_document = impl.createDocument(None, "parameters", None) - xml_parameters = xml_document.documentElement - for group in groups: - xml_group = xml_document.createElement("group") - xml_group.setAttribute("name", group.GetName()) - xml_parameters.appendChild(xml_group) - for param in group.GetParams(): - xml_param = xml_document.createElement("parameter") - xml_group.appendChild(xml_param) - for code in param.GetFieldCodes(): - value = param.GetFieldValue(code) - xml_field = xml_document.createElement(code) - xml_param.appendChild(xml_field) - xml_value = xml_document.createTextNode(value) - xml_field.appendChild(xml_value) - return xml_document.toprettyxml(indent=" ", newl="\n", encoding="utf-8") diff --git a/Tools/px4params/xmlrpc.sh b/Tools/px4params/xmlrpc.sh index 36c52ff71..efd177f46 100644 --- a/Tools/px4params/xmlrpc.sh +++ b/Tools/px4params/xmlrpc.sh @@ -2,4 +2,4 @@ python px_process_params.py rm cookies.txt curl --cookie cookies.txt --cookie-jar cookies.txt --user-agent Mozilla/4.0 --data "u=$XMLRPCUSER&p=$XMLRPCPASS" https://pixhawk.org/start?do=login -curl -k --cookie cookies.txt -H "Content-Type: application/xml" -X POST --data-binary @parameters.wiki "https://pixhawk.org/lib/exe/xmlrpc.php" +curl -k --cookie cookies.txt -H "Content-Type: application/xml" -X POST --data-binary @parameters.wikirpc.xml "https://pixhawk.org/lib/exe/xmlrpc.php" -- cgit v1.2.3