mirror of https://github.com/ArduPilot/ardupilot
Tools: param_metadata: remove use of dirname when creating Vehicle
So a Vehicle object takes a truename - i.e. Copter, not ArduCopter, but can also take a "reference", which is used for e.g. constructing RST tags.
This commit is contained in:
parent
3ea9307419
commit
c18c4ad6ec
|
@ -51,7 +51,7 @@ DO NOT EDIT
|
|||
pass
|
||||
|
||||
def emit(self, g):
|
||||
tag = '%s Parameters' % g.name
|
||||
tag = '%s Parameters' % g.reference
|
||||
t = '\n\n<h1>%s</h1>\n' % tag
|
||||
|
||||
for param in g.params:
|
||||
|
|
|
@ -33,10 +33,7 @@ class JSONEmit(Emit):
|
|||
# Copy content to avoid any modification
|
||||
g = copy.deepcopy(g)
|
||||
|
||||
# Get vehicle name
|
||||
if 'truename' in g.__dict__:
|
||||
self.name = g.__dict__['truename']
|
||||
self.content[self.name] = {}
|
||||
self.content[self.name] = {}
|
||||
|
||||
# Check all params available
|
||||
for param in g.params:
|
||||
|
|
|
@ -48,16 +48,16 @@ class MDEmit(Emit):
|
|||
def emit(self, g):
|
||||
nparam = False # Flag indicating this is a parameter group with redundant information (ie RCn_, SERVOn_)
|
||||
|
||||
if g.name == 'ArduSub':
|
||||
if g.reference == 'ArduSub':
|
||||
self.blacklist = sub_blacklist
|
||||
|
||||
if self.blacklist is not None and g.name in self.blacklist:
|
||||
if self.blacklist is not None and g.reference in self.blacklist:
|
||||
return
|
||||
|
||||
pname = g.name
|
||||
pname = g.reference
|
||||
|
||||
# Check to see this is a parameter group with redundant information
|
||||
rename = re.sub('\d+', 'n', g.name)
|
||||
rename = re.sub('\d+', 'n', g.reference)
|
||||
if rename in nparams:
|
||||
if rename in self.nparams:
|
||||
return
|
||||
|
|
|
@ -6,19 +6,24 @@ class Parameter(object):
|
|||
|
||||
|
||||
class Vehicle(object):
|
||||
def __init__(self, name, path, truename=None):
|
||||
if truename is not None:
|
||||
self.truename = truename
|
||||
def __init__(self, name, path, reference=None):
|
||||
self.name = name
|
||||
self.path = path
|
||||
self.reference = reference
|
||||
if reference is None:
|
||||
self.reference = self.truename
|
||||
self.params = []
|
||||
|
||||
|
||||
class Library(object):
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.set_name(name)
|
||||
self.params = []
|
||||
|
||||
def set_name(self, name):
|
||||
self.name = name
|
||||
self.reference = name
|
||||
|
||||
known_param_fields = [
|
||||
'Description',
|
||||
'DisplayName',
|
||||
|
|
|
@ -123,12 +123,14 @@ truename_map = {
|
|||
"AP_Periph": "AP_Periph",
|
||||
}
|
||||
valid_truenames = frozenset(truename_map.values())
|
||||
truename = truename_map.get(args.vehicle, args.vehicle)
|
||||
|
||||
vehicle_path = find_vehicle_parameter_filepath(args.vehicle)
|
||||
|
||||
name = os.path.basename(os.path.dirname(vehicle_path))
|
||||
basename = os.path.basename(os.path.dirname(vehicle_path))
|
||||
path = os.path.normpath(os.path.dirname(vehicle_path))
|
||||
vehicle = Vehicle(name, path, truename_map[name])
|
||||
reference = basename # so links don't break we use ArduCopter
|
||||
vehicle = Vehicle(truename, path, reference=reference)
|
||||
debug('Found vehicle type %s' % vehicle.name)
|
||||
|
||||
|
||||
|
@ -168,7 +170,7 @@ def process_vehicle(vehicle):
|
|||
raise ValueError("Invalid only_vehicle %s" % only_vehicle)
|
||||
if vehicle.truename not in only_vehicles_list:
|
||||
continue
|
||||
p = Parameter(vehicle.name+":"+param_name, current_file)
|
||||
p = Parameter(vehicle.reference+":"+param_name, current_file)
|
||||
debug(p.name + ' ')
|
||||
global current_param
|
||||
current_param = p.name
|
||||
|
@ -237,7 +239,7 @@ def process_library(vehicle, library, pathprefix=None):
|
|||
for only_vehicle in only_vehicles_list:
|
||||
if only_vehicle not in valid_truenames:
|
||||
raise ValueError("Invalid only_vehicle %s" % only_vehicle)
|
||||
if vehicle.truename not in only_vehicles_list:
|
||||
if vehicle.name not in only_vehicles_list:
|
||||
continue
|
||||
p = Parameter(library.name+param_name, current_file)
|
||||
debug(p.name + ' ')
|
||||
|
@ -264,11 +266,11 @@ def process_library(vehicle, library, pathprefix=None):
|
|||
delta = set(only_for_vehicles) - set(truename_map.values())
|
||||
if len(delta):
|
||||
error("Unknown vehicles (%s)" % delta)
|
||||
debug("field[0]=%s vehicle=%s truename=%s field[1]=%s only_for_vehicles=%s\n" %
|
||||
(field[0], vehicle.name, vehicle.truename, field[1], str(only_for_vehicles)))
|
||||
debug("field[0]=%s vehicle=%s field[1]=%s only_for_vehicles=%s\n" %
|
||||
(field[0], vehicle.name, field[1], str(only_for_vehicles)))
|
||||
value = re.sub('@PREFIX@', library.name, field[2])
|
||||
if field[0] in ['Values', 'Bitmask']:
|
||||
if vehicle.truename in only_for_vehicles:
|
||||
if vehicle.name in only_for_vehicles:
|
||||
this_vehicle_values_seen = True
|
||||
this_vehicle_value = value
|
||||
if len(only_for_vehicles) > 1:
|
||||
|
@ -314,7 +316,7 @@ def process_library(vehicle, library, pathprefix=None):
|
|||
error("unknown parameter metadata field '%s'" % field[0])
|
||||
if not any(lib.name == parsed_l.name for parsed_l in libraries):
|
||||
if do_append:
|
||||
lib.name = library.name + lib.name
|
||||
lib.set_name(library.name + lib.name)
|
||||
debug("Group name: %s" % lib.name)
|
||||
process_library(vehicle, lib, os.path.dirname(libraryfname))
|
||||
if do_append:
|
||||
|
|
|
@ -190,8 +190,8 @@ This list is automatically generated from the latest ardupilot source code, and
|
|||
return self.tablify(rows, headings=render_info["headings"])
|
||||
|
||||
def emit(self, g):
|
||||
tag = '%s Parameters' % self.escape(g.name)
|
||||
reference = "parameters_" + g.name
|
||||
tag = '%s Parameters' % self.escape(g.reference)
|
||||
reference = "parameters_" + g.reference
|
||||
|
||||
field_table_info = {
|
||||
"Values": {
|
||||
|
|
|
@ -33,7 +33,7 @@ class XmlEmit(Emit):
|
|||
self.current_element = self.libraries
|
||||
|
||||
def emit(self, g):
|
||||
xml_parameters = etree.SubElement(self.current_element, 'parameters', name=g.name) # i.e. ArduPlane
|
||||
xml_parameters = etree.SubElement(self.current_element, 'parameters', name=g.reference) # i.e. ArduPlane
|
||||
|
||||
for param in g.params:
|
||||
# Begin our parameter node
|
||||
|
|
|
@ -43,7 +43,7 @@ class XmlEmitMP(Emit):
|
|||
def emit(self, g):
|
||||
t = ""
|
||||
if not self.skip_name:
|
||||
self.gname = g.name
|
||||
self.gname = g.reference
|
||||
if self.gname == "ArduCopter":
|
||||
self.gname = "ArduCopter2"
|
||||
if self.gname == "APMrover2" or self.gname == "Rover":
|
||||
|
|
Loading…
Reference in New Issue