parameters: move XML injection to the group level (#15403)

So that they are also in the markdown and json output.
This commit is contained in:
Hamish Willee 2020-07-24 21:45:53 +10:00 committed by GitHub
parent 400d97e60c
commit 4ade24869f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 9 deletions

View File

@ -0,0 +1,71 @@
#!/usr/bin/env python
# Injects params from XML file into a param_group
#
from __future__ import print_function
from px4params import srcscanner, srcparser, xmlout, markdownout
from .srcparser import ParameterGroup, Parameter
import xml.etree.ElementTree as ET
import sys
class XMLInject():
def __init__(self, injected_xml_filename):
self.groups=[]
valid_parameter_attributes = set(["category", "default", "name", "type", "volatile"])
valid_field_tags = set(["board","short_desc", "long_desc", "min", "max", "unit", "decimal", "increment", "reboot_required"])
valid_other_top_level_tags = set(["group","values"])
importtree = ET.parse(injected_xml_filename)
injectgroups = importtree.getroot().findall("group")
not_handled_parameter_tags=set()
not_handled_parameter_attributes=set()
for igroup in injectgroups:
group_name=igroup.get('name')
imported_group = ParameterGroup(group_name)
no_code_generation=igroup.get('no_code_generation')
if no_code_generation:
imported_group.no_code_generation=no_code_generation
for iparam in igroup:
param_name=iparam.get('name')
param_type=iparam.get('type')
new_param= Parameter(param_name, param_type)
#get other param info stored as attributes
for param_attrib in iparam.attrib:
if param_attrib not in valid_parameter_attributes:
not_handled_parameter_attributes.add(param_attrib)
elif param_attrib == 'category':
new_param.SetCategory(iparam.get('category'))
elif param_attrib == 'default':
new_param.default = iparam.get('default')
elif param_attrib == 'volatile':
new_param.SetVolatile()
#get param info stored as child tags
for child in iparam:
if child.tag in valid_field_tags:
new_param.SetField(child.tag, child.text)
elif child.tag == 'values':
for value in child:
new_param.SetEnumValue(value.get('code'), value.text)
elif child.tag == 'bitmask':
for bit in child:
new_param.SetBitmaskBit(bit.get('index'), bit.text)
else:
not_handled_parameter_tags.add(child.tag)
imported_group.AddParameter(new_param)
self.groups.append(imported_group)
if not_handled_parameter_tags or not_handled_parameter_attributes:
print("WARNING: Injected file parameter has unhandled child tags: %s" % not_handled_parameter_tags)
print("WARNING: Injected file parameter has unhandled attributes: %s" % not_handled_parameter_attributes)
def injected(self):
return self.groups

View File

@ -11,6 +11,7 @@ class ParameterGroup(object):
"""
def __init__(self, name):
self.name = name
self.no_code_generation = False #for injected parameters
self.params = []
def AddParameter(self, param):

View File

@ -18,7 +18,7 @@ def indent(elem, level=0):
class XMLOutput():
def __init__(self, groups, board, inject_xml_file_name):
def __init__(self, groups, board):
xml_parameters = ET.Element("parameters")
xml_version = ET.SubElement(xml_parameters, "version")
xml_version.text = "3"
@ -26,15 +26,13 @@ class XMLOutput():
xml_version.text = "1"
xml_version = ET.SubElement(xml_parameters, "parameter_version_minor")
xml_version.text = "15"
importtree = ET.parse(inject_xml_file_name)
injectgroups = importtree.getroot().findall("group")
for igroup in injectgroups:
xml_parameters.append(igroup)
last_param_name = ""
board_specific_param_set = False
for group in groups:
xml_group = ET.SubElement(xml_parameters, "group")
xml_group.attrib["name"] = group.GetName()
if group.no_code_generation:
xml_group.attrib["no_code_generation"] = group.no_code_generation
for param in group.GetParams():
if (last_param_name == param.GetName() and not board_specific_param_set) or last_param_name != param.GetName():
xml_param = ET.SubElement(xml_group, "parameter")

View File

@ -47,7 +47,7 @@ from __future__ import print_function
import sys
import os
import argparse
from px4params import srcscanner, srcparser, xmlout, markdownout
from px4params import srcscanner, srcparser, injectxmlparams, xmlout, markdownout
import re
import json
@ -118,6 +118,12 @@ def main():
if len(param_groups) == 0:
print("Warning: no parameters found")
#inject parameters at front of set
cur_dir = os.path.dirname(os.path.realpath(__file__))
groups_to_inject = injectxmlparams.XMLInject(os.path.join(cur_dir, args.inject_xml)).injected()
param_groups=groups_to_inject+param_groups
override_dict = json.loads(args.overrides)
if len(override_dict.keys()) > 0:
for group in param_groups:
@ -132,9 +138,7 @@ def main():
if args.xml:
if args.verbose:
print("Creating XML file " + args.xml)
cur_dir = os.path.dirname(os.path.realpath(__file__))
out = xmlout.XMLOutput(param_groups, args.board,
os.path.join(cur_dir, args.inject_xml))
out = xmlout.XMLOutput(param_groups, args.board)
out.Save(args.xml)
# Output to Markdown/HTML tables