mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
fix(tools): preserve newlines and float values in param migration
- migrate_c_params.py: preserve newlines and paragraph breaks in long descriptions, use YAML block scalars for multi-line strings - generate_params.py: support @value tags on float type parameters (fixes RC*_REV enum values being lost during yaml generation)
This commit is contained in:
parent
d5974a18d9
commit
6966d67c1f
@ -128,6 +128,9 @@ class SourceParser:
|
||||
# start waiting for the next part - long comment.
|
||||
if state == "wait-short-end":
|
||||
state = "wait-long"
|
||||
elif state == "wait-long-end":
|
||||
# Preserve paragraph breaks in long description
|
||||
long_desc += "\n"
|
||||
else:
|
||||
m = self.re_comment_tag.match(comment_content)
|
||||
if m:
|
||||
@ -208,8 +211,7 @@ class SourceParser:
|
||||
raise Exception('short description too long (150 max, is {:}, parameter: {:})'.format(len(short_desc), name))
|
||||
param.fields["short_desc"] = self.re_remove_dots.sub('', short_desc)
|
||||
if long_desc is not None:
|
||||
long_desc = self.re_remove_carriage_return.sub(' ', long_desc)
|
||||
param.fields["long_desc"] = long_desc
|
||||
param.fields["long_desc"] = long_desc.rstrip('\n')
|
||||
for tag in tags:
|
||||
if tag == "group":
|
||||
group = tags[tag]
|
||||
@ -407,7 +409,15 @@ def generate_yaml(filename: str, groups: list[ParameterGroup]) -> str:
|
||||
g["definitions"][parameter.name] = p
|
||||
data["parameters"].append(g)
|
||||
|
||||
return yaml.dump(data, sort_keys=False)
|
||||
# Use block scalar style for multi-line strings
|
||||
class BlockStyleDumper(yaml.SafeDumper):
|
||||
pass
|
||||
def str_representer(dumper, data):
|
||||
if '\n' in data:
|
||||
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
|
||||
return dumper.represent_scalar('tag:yaml.org,2002:str', data)
|
||||
BlockStyleDumper.add_representer(str, str_representer)
|
||||
return yaml.dump(data, Dumper=BlockStyleDumper, sort_keys=False)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@ -108,7 +108,7 @@ def parse_yaml_parameters_config(yaml_config, ethernet_supported):
|
||||
tags = '@group {:}'.format(param_group)
|
||||
if param['type'] == 'enum':
|
||||
param_type = 'INT32'
|
||||
for key in param['values']:
|
||||
for key in sorted(param['values'], key=float):
|
||||
tags += '\n * @value {:} {:}'.format(key, param['values'][key])
|
||||
elif param['type'] == 'bitmask':
|
||||
param_type = 'INT32'
|
||||
@ -124,6 +124,9 @@ def parse_yaml_parameters_config(yaml_config, ethernet_supported):
|
||||
param_type = 'INT32'
|
||||
elif param['type'] == 'float':
|
||||
param_type = 'FLOAT'
|
||||
if 'values' in param:
|
||||
for key in sorted(param['values'], key=float):
|
||||
tags += '\n * @value {:} {:}'.format(key, param['values'][key])
|
||||
else:
|
||||
raise Exception("unknown param type {:}".format(param['type']))
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user