mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
Airframes tool: Support basic pruning
This commit is contained in:
parent
f67e44215f
commit
f23881d8ab
@ -4,6 +4,7 @@ import os
|
||||
|
||||
class RCOutput():
|
||||
def __init__(self, groups, board):
|
||||
|
||||
result = ( "#\n"
|
||||
"#\n"
|
||||
"# THIS FILE IS AUTO-GENERATED. DO NOT EDIT!\n"
|
||||
@ -31,6 +32,12 @@ class RCOutput():
|
||||
for group in groups:
|
||||
result += "# GROUP: %s\n\n" % group.GetName()
|
||||
for param in group.GetParams():
|
||||
excluded = False
|
||||
for code in param.GetArchCodes():
|
||||
if "{0}".format(code) == board and param.GetArchValue(code) == "exclude":
|
||||
excluded = True
|
||||
if excluded:
|
||||
continue
|
||||
path = os.path.split(param.GetPath())[1]
|
||||
id_val = param.GetId()
|
||||
name = param.GetFieldValue("short_desc")
|
||||
|
||||
@ -50,6 +50,7 @@ class Parameter(object):
|
||||
def __init__(self, path, name, airframe_type, airframe_id, maintainer):
|
||||
self.fields = {}
|
||||
self.outputs = {}
|
||||
self.archs = {}
|
||||
self.path = path
|
||||
self.name = name
|
||||
self.type = airframe_type
|
||||
@ -83,6 +84,12 @@ class Parameter(object):
|
||||
"""
|
||||
self.outputs[code] = value
|
||||
|
||||
def SetArch(self, code, value):
|
||||
"""
|
||||
Set named arch value
|
||||
"""
|
||||
self.archs[code] = value
|
||||
|
||||
def GetFieldCodes(self):
|
||||
"""
|
||||
Return list of existing field codes in convenient order
|
||||
@ -121,6 +128,25 @@ class Parameter(object):
|
||||
return ""
|
||||
return self.outputs.get(code)
|
||||
|
||||
def GetArchCodes(self):
|
||||
"""
|
||||
Return list of existing arch codes in convenient order
|
||||
"""
|
||||
keys = self.archs.keys()
|
||||
keys = sorted(keys)
|
||||
keys = sorted(keys, key=lambda x: self.priority.get(x, 0), reverse=True)
|
||||
return keys
|
||||
|
||||
def GetArchValue(self, code):
|
||||
"""
|
||||
Return value of the given arch code or None if not found.
|
||||
"""
|
||||
fv = self.archs.get(code)
|
||||
if not fv:
|
||||
# required because python 3 sorted does not accept None
|
||||
return ""
|
||||
return self.archs.get(code)
|
||||
|
||||
class SourceParser(object):
|
||||
"""
|
||||
Parses provided data and stores all found parameters internally.
|
||||
@ -136,7 +162,7 @@ class SourceParser(object):
|
||||
re_remove_dots = re.compile(r'\.+$')
|
||||
re_remove_carriage_return = re.compile('\n+')
|
||||
|
||||
valid_tags = set(["url", "maintainer", "output", "name", "type"])
|
||||
valid_tags = set(["url", "maintainer", "output", "arch", "name", "type"])
|
||||
|
||||
# Order of parameter groups
|
||||
priority = {
|
||||
@ -173,6 +199,7 @@ class SourceParser(object):
|
||||
state = None
|
||||
tags = {}
|
||||
outputs = {}
|
||||
archs = {}
|
||||
for line in self.re_split_lines.split(contents):
|
||||
line = line.strip()
|
||||
# Ignore empty lines
|
||||
@ -204,6 +231,9 @@ class SourceParser(object):
|
||||
if (tag == "output"):
|
||||
key, text = desc.split(' ', 1)
|
||||
outputs[key] = text;
|
||||
elif (tag == "board"):
|
||||
key, text = desc.split(' ', 1)
|
||||
archs[key] = text;
|
||||
else:
|
||||
tags[tag] = desc
|
||||
current_tag = tag
|
||||
@ -281,13 +311,17 @@ class SourceParser(object):
|
||||
for output in outputs:
|
||||
param.SetOutput(output, outputs[output])
|
||||
|
||||
# Store outputs
|
||||
for arch in archs:
|
||||
param.SetArch(arch, archs[arch])
|
||||
|
||||
# Store the parameter
|
||||
if airframe_type not in self.param_groups:
|
||||
self.param_groups[airframe_type] = ParameterGroup(airframe_type)
|
||||
self.param_groups[airframe_type].AddParameter(param)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def IsNumber(self, numberString):
|
||||
try:
|
||||
float(numberString)
|
||||
|
||||
@ -86,7 +86,15 @@ class XMLOutput():
|
||||
else:
|
||||
xml_group.attrib["image"] = "AirframeUnknown"
|
||||
for param in group.GetParams():
|
||||
if (last_param_name == param.GetName() and not board_specific_param_set) or last_param_name != param.GetName():
|
||||
|
||||
# check if there is an exclude tag for this airframe
|
||||
excluded = False
|
||||
for code in param.GetArchCodes():
|
||||
if "CONFIG_ARCH_BOARD_{0}".format(code) == board and param.GetArchValue(code) == "exclude":
|
||||
excluded = True
|
||||
|
||||
if not excluded and ((last_param_name == param.GetName() and not board_specific_param_set) or last_param_name != param.GetName()):
|
||||
#print("generating: {0} {1}".format(param.GetName(), excluded))
|
||||
xml_param = ET.SubElement(xml_group, "airframe")
|
||||
xml_param.attrib["name"] = param.GetName()
|
||||
xml_param.attrib["id"] = param.GetId()
|
||||
@ -94,16 +102,16 @@ class XMLOutput():
|
||||
last_param_name = param.GetName()
|
||||
for code in param.GetFieldCodes():
|
||||
value = param.GetFieldValue(code)
|
||||
if code == "board":
|
||||
if value == board:
|
||||
board_specific_param_set = True
|
||||
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 code == "board":
|
||||
# if value == board:
|
||||
# board_specific_param_set = True
|
||||
# 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
|
||||
for code in param.GetOutputCodes():
|
||||
value = param.GetOutputValue(code)
|
||||
valstrs = value.split(";")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user