mirror of https://github.com/ArduPilot/ardupilot
autotest: fixed parameter generation for recursive libraries
This commit is contained in:
parent
90d9e74054
commit
de59f27e14
|
@ -105,98 +105,126 @@ for vehicle in vehicles:
|
|||
|
||||
debug("Found %u documented libraries" % len(libraries))
|
||||
|
||||
alllibs = libraries[:]
|
||||
|
||||
def process_library(library, pathprefix=None):
|
||||
'''process one library'''
|
||||
paths = library.Path.split(',')
|
||||
for path in paths:
|
||||
path = path.strip()
|
||||
debug("\n Processing file '%s'" % path)
|
||||
if pathprefix is not None:
|
||||
libraryfname = os.path.join(pathprefix, path)
|
||||
elif path.find('/') == -1:
|
||||
if len(vehicles) != 1:
|
||||
print("Unable to handle multiple vehicles with .pde library")
|
||||
continue
|
||||
libraryfname = os.path.join(vehicles[0].path, path)
|
||||
else:
|
||||
libraryfname = os.path.normpath(os.path.join(apm_path + '/libraries/' + path))
|
||||
if path and os.path.exists(libraryfname):
|
||||
f = open(libraryfname)
|
||||
p_text = f.read()
|
||||
f.close()
|
||||
else:
|
||||
error("Path %s not found for library %s" % (path, library.name))
|
||||
continue
|
||||
|
||||
param_matches = prog_group_param.findall(p_text)
|
||||
debug("Found %u documented parameters" % len(param_matches))
|
||||
for param_match in param_matches:
|
||||
p = Parameter(library.name+param_match[0])
|
||||
debug(p.name + ' ')
|
||||
field_text = param_match[1]
|
||||
fields = prog_param_fields.findall(field_text)
|
||||
for field in fields:
|
||||
if field[0] in known_param_fields:
|
||||
setattr(p, field[0], field[1])
|
||||
else:
|
||||
error("unknown parameter metadata field %s" % field[0])
|
||||
library.params.append(p)
|
||||
|
||||
group_matches = prog_groups.findall(p_text)
|
||||
debug("Found %u groups" % len(group_matches))
|
||||
debug(group_matches)
|
||||
for group_match in group_matches:
|
||||
group = group_match[0]
|
||||
debug("Group: %s" % group)
|
||||
l = Library(group)
|
||||
fields = prog_param_fields.findall(group_match[1])
|
||||
for field in fields:
|
||||
if field[0] in known_group_fields:
|
||||
setattr(l, field[0], field[1])
|
||||
else:
|
||||
error("unknown parameter metadata field '%s'" % field[0])
|
||||
if not any(l.name == parsed_l.name for parsed_l in libraries):
|
||||
l.name = library.name + l.name
|
||||
debug("Group name: %s" % l.name)
|
||||
process_library(l, os.path.dirname(libraryfname))
|
||||
alllibs.append(l)
|
||||
|
||||
for library in libraries:
|
||||
debug("===\n\n\nProcessing library %s" % library.name)
|
||||
|
||||
if hasattr(library, 'Path'):
|
||||
paths = library.Path.split(',')
|
||||
for path in paths:
|
||||
path = path.strip()
|
||||
debug("\n Processing file '%s'" % path)
|
||||
if path.endswith('.pde') or path.find('/') == -1:
|
||||
if len(vehicles) != 1:
|
||||
print("Unable to handle multiple vehicles with .pde library")
|
||||
continue
|
||||
libraryfname = os.path.join(vehicles[0].path, path)
|
||||
else:
|
||||
libraryfname = os.path.normpath(os.path.join(apm_path + '/libraries/' + path))
|
||||
if path and os.path.exists(libraryfname):
|
||||
f = open(libraryfname)
|
||||
p_text = f.read()
|
||||
f.close()
|
||||
else:
|
||||
error("Path %s not found for library %s" % (path, library.name))
|
||||
continue
|
||||
|
||||
param_matches = prog_group_param.findall(p_text)
|
||||
debug("Found %u documented parameters" % len(param_matches))
|
||||
for param_match in param_matches:
|
||||
p = Parameter(library.name+param_match[0])
|
||||
debug(p.name + ' ')
|
||||
field_text = param_match[1]
|
||||
fields = prog_param_fields.findall(field_text)
|
||||
for field in fields:
|
||||
if field[0] in known_param_fields:
|
||||
setattr(p, field[0], field[1])
|
||||
else:
|
||||
error("unknown parameter metadata field %s" % field[0])
|
||||
|
||||
library.params.append(p)
|
||||
process_library(library)
|
||||
else:
|
||||
error("Skipped: no Path found")
|
||||
|
||||
debug("Processed %u documented parameters" % len(library.params))
|
||||
|
||||
def is_number(numberString):
|
||||
try:
|
||||
float(numberString)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
libraries = alllibs
|
||||
|
||||
def validate(param):
|
||||
"""
|
||||
Validates the parameter meta data.
|
||||
"""
|
||||
# Validate values
|
||||
if (hasattr(param, "Range")):
|
||||
rangeValues = param.__dict__["Range"].split(" ")
|
||||
if (len(rangeValues) != 2):
|
||||
error("Invalid Range values for %s" % (param.name))
|
||||
return
|
||||
min_value = rangeValues[0]
|
||||
max_value = rangeValues[1]
|
||||
if not is_number(min_value):
|
||||
error("Min value not number: %s %s" % (param.name, min_value))
|
||||
return
|
||||
if not is_number(max_value):
|
||||
error("Max value not number: %s %s" % (param.name, max_value))
|
||||
return
|
||||
def is_number(numberString):
|
||||
try:
|
||||
float(numberString)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
def validate(param):
|
||||
"""
|
||||
Validates the parameter meta data.
|
||||
"""
|
||||
# Validate values
|
||||
if (hasattr(param, "Range")):
|
||||
rangeValues = param.__dict__["Range"].split(" ")
|
||||
if (len(rangeValues) != 2):
|
||||
error("Invalid Range values for %s" % (param.name))
|
||||
return
|
||||
min_value = rangeValues[0]
|
||||
max_value = rangeValues[1]
|
||||
if not is_number(min_value):
|
||||
error("Min value not number: %s %s" % (param.name, min_value))
|
||||
return
|
||||
if not is_number(max_value):
|
||||
error("Max value not number: %s %s" % (param.name, max_value))
|
||||
return
|
||||
|
||||
for vehicle in vehicles:
|
||||
for param in vehicle.params:
|
||||
validate(param)
|
||||
|
||||
for library in libraries:
|
||||
for param in library.params:
|
||||
validate(param)
|
||||
|
||||
def do_emit(emit):
|
||||
emit.set_annotate_with_vehicle(len(vehicles) > 1)
|
||||
for vehicle in vehicles:
|
||||
for param in vehicle.params:
|
||||
validate(param)
|
||||
emit.emit(vehicle, f)
|
||||
|
||||
emit.start_libraries()
|
||||
|
||||
for library in libraries:
|
||||
for param in library.params:
|
||||
validate(param)
|
||||
if library.params:
|
||||
emit.emit(library, f)
|
||||
|
||||
def do_emit(emit):
|
||||
emit.set_annotate_with_vehicle(len(vehicles) > 1)
|
||||
for vehicle in vehicles:
|
||||
emit.emit(vehicle, f)
|
||||
emit.close()
|
||||
|
||||
emit.start_libraries()
|
||||
|
||||
for library in libraries:
|
||||
if library.params:
|
||||
emit.emit(library, f)
|
||||
|
||||
emit.close()
|
||||
|
||||
do_emit(XmlEmit())
|
||||
do_emit(WikiEmit())
|
||||
do_emit(HtmlEmit())
|
||||
do_emit(RSTEmit())
|
||||
do_emit(XmlEmit())
|
||||
do_emit(WikiEmit())
|
||||
do_emit(HtmlEmit())
|
||||
do_emit(RSTEmit())
|
||||
|
||||
sys.exit(error_count)
|
||||
|
|
Loading…
Reference in New Issue