Add support for board attribute to parse output

This allows for writing parameter meta data which is specific to a
board type
This commit is contained in:
Don Gagne
2015-04-21 12:31:08 -07:00
parent 39f6e13c18
commit 6bf0a2618b
4 changed files with 53 additions and 33 deletions
+2 -2
View File
@@ -12,11 +12,11 @@ class DokuWikiTablesOutput():
result += "^ Name ^ Description ^ Min ^ Max ^ Default ^\n" result += "^ Name ^ Description ^ Min ^ Max ^ Default ^\n"
result += "^ ::: ^ Comment ^^^^\n" result += "^ ::: ^ Comment ^^^^\n"
for param in group.GetParams(): for param in group.GetParams():
code = param.GetFieldValue("code") code = param.GetName()
def_val = param.GetDefault()
name = param.GetFieldValue("short_desc") name = param.GetFieldValue("short_desc")
min_val = param.GetFieldValue("min") min_val = param.GetFieldValue("min")
max_val = param.GetFieldValue("max") max_val = param.GetFieldValue("max")
def_val = param.GetFieldValue("default")
long_desc = param.GetFieldValue("long_desc") long_desc = param.GetFieldValue("long_desc")
if name == code: if name == code:
+21 -16
View File
@@ -37,20 +37,30 @@ class Parameter(object):
# Define sorting order of the fields # Define sorting order of the fields
priority = { priority = {
"code": 10, "board": 9,
"type": 9,
"short_desc": 8, "short_desc": 8,
"long_desc": 7, "long_desc": 7,
"default": 6,
"min": 5, "min": 5,
"max": 4, "max": 4,
"unit": 3, "unit": 3,
# all others == 0 (sorted alphabetically) # all others == 0 (sorted alphabetically)
} }
def __init__(self): def __init__(self, name, type, default = ""):
self.fields = {} self.fields = {}
self.name = name
self.type = type
self.default = default
def GetName(self):
return self.name
def GetType(self):
return self.type
def GetDefault(self):
return self.default
def SetField(self, code, value): def SetField(self, code, value):
""" """
Set named field value Set named field value
@@ -88,7 +98,7 @@ class SourceParser(object):
re_is_a_number = re.compile(r'^-?[0-9\.]') re_is_a_number = re.compile(r'^-?[0-9\.]')
re_remove_dots = re.compile(r'\.+$') re_remove_dots = re.compile(r'\.+$')
valid_tags = set(["group", "min", "max", "unit"]) valid_tags = set(["group", "board", "min", "max", "unit"])
# Order of parameter groups # Order of parameter groups
priority = { priority = {
@@ -177,15 +187,12 @@ class SourceParser(object):
# Non-empty line outside the comment # Non-empty line outside the comment
m = self.re_parameter_definition.match(line) m = self.re_parameter_definition.match(line)
if m: if m:
tp, code, defval = m.group(1, 2, 3) tp, name, defval = m.group(1, 2, 3)
# Remove trailing type specifier from numbers: 0.1f => 0.1 # Remove trailing type specifier from numbers: 0.1f => 0.1
if self.re_is_a_number.match(defval): if self.re_is_a_number.match(defval):
defval = self.re_cut_type_specifier.sub('', defval) defval = self.re_cut_type_specifier.sub('', defval)
param = Parameter() param = Parameter(name, tp, defval)
param.SetField("code", code) param.SetField("short_desc", name)
param.SetField("short_desc", code)
param.SetField("type", tp)
param.SetField("default", defval)
# If comment was found before the parameter declaration, # If comment was found before the parameter declaration,
# inject its data into the newly created parameter. # inject its data into the newly created parameter.
group = "Miscellaneous" group = "Miscellaneous"
@@ -211,11 +218,9 @@ class SourceParser(object):
# Nasty code dup, but this will all go away soon, so quick and dirty (DonLakeFlyer) # Nasty code dup, but this will all go away soon, so quick and dirty (DonLakeFlyer)
m = self.re_px4_parameter_definition.match(line) m = self.re_px4_parameter_definition.match(line)
if m: if m:
tp, code = m.group(1, 2) tp, name = m.group(1, 2)
param = Parameter() param = Parameter(name, tp)
param.SetField("code", code) param.SetField("short_desc", name)
param.SetField("short_desc", code)
param.SetField("type", tp)
# If comment was found before the parameter declaration, # If comment was found before the parameter declaration,
# inject its data into the newly created parameter. # inject its data into the newly created parameter.
group = "Miscellaneous" group = "Miscellaneous"
+24 -14
View File
@@ -18,26 +18,36 @@ def indent(elem, level=0):
class XMLOutput(): class XMLOutput():
def __init__(self, groups): def __init__(self, groups, board):
xml_parameters = ET.Element("parameters") xml_parameters = ET.Element("parameters")
xml_version = ET.SubElement(xml_parameters, "version") xml_version = ET.SubElement(xml_parameters, "version")
xml_version.text = "2" xml_version.text = "3"
last_param_name = ""
board_specific_param_set = False
for group in groups: for group in groups:
xml_group = ET.SubElement(xml_parameters, "group") xml_group = ET.SubElement(xml_parameters, "group")
xml_group.attrib["name"] = group.GetName() xml_group.attrib["name"] = group.GetName()
for param in group.GetParams(): for param in group.GetParams():
xml_param = ET.SubElement(xml_group, "parameter") if (last_param_name == param.GetName() and not board_specific_param_set) or last_param_name != param.GetName():
for code in param.GetFieldCodes(): xml_param = ET.SubElement(xml_group, "parameter")
value = param.GetFieldValue(code) xml_param.attrib["name"] = param.GetName()
if code == "code": xml_param.attrib["default"] = param.GetDefault()
xml_param.attrib["name"] = value xml_param.attrib["type"] = param.GetType()
elif code == "default": last_param_name = param.GetName()
xml_param.attrib["default"] = value for code in param.GetFieldCodes():
elif code == "type": value = param.GetFieldValue(code)
xml_param.attrib["type"] = value if code == "board":
else: if value == board:
xml_field = ET.SubElement(xml_param, code) board_specific_param_set = True
xml_field.text = value xml_field = ET.SubElement(xml_param, code)
xml_field.text = value
else:
xml_group.remove(xml_param)
else:
xml_field = ET.SubElement(xml_param, code)
xml_field.text = value
if last_param_name != param.GetName():
board_specific_param_set = False
indent(xml_parameters) indent(xml_parameters)
self.xml_document = ET.ElementTree(xml_parameters) self.xml_document = ET.ElementTree(xml_parameters)
+6 -1
View File
@@ -65,6 +65,11 @@ def main():
metavar="FILENAME", metavar="FILENAME",
help="Create XML file" help="Create XML file"
" (default FILENAME: parameters.xml)") " (default FILENAME: parameters.xml)")
parser.add_argument("-b", "--board",
nargs='?',
const="",
metavar="BOARD",
help="Board to create xml parameter xml for")
parser.add_argument("-w", "--wiki", parser.add_argument("-w", "--wiki",
nargs='?', nargs='?',
const="parameters.wiki", const="parameters.wiki",
@@ -116,7 +121,7 @@ def main():
# Output to XML file # Output to XML file
if args.xml: if args.xml:
print("Creating XML file " + args.xml) print("Creating XML file " + args.xml)
out = xmlout.XMLOutput(param_groups) out = xmlout.XMLOutput(param_groups, args.board)
out.Save(args.xml) out.Save(args.xml)
# Output to DokuWiki tables # Output to DokuWiki tables