from xml.sax.saxutils import escape import codecs import os import html class MarkdownTablesOutput(): def __init__(self, groups, board, image_path): result = """# Airframes Reference :::note **This list is [auto-generated](https://github.com/PX4/PX4-Autopilot/blob/main/Tools/px4airframes/markdownout.py) from the source code** using the build command: `make airframe_metadata`. ::: This page lists all supported airframes and types including the motor assignment and numbering. The motors in **green** rotate clockwise, the ones in **blue** counterclockwise. **AUX** channels may not be present on some flight controllers. If present, PWM AUX channels are commonly labelled **AUX OUT**. \n\n""" type_set = set() if len(image_path) > 0 and image_path[-1] != '/': image_path = image_path + '/' for group in groups: if group.GetClass() not in type_set: result += '## %s\n\n' % group.GetClass() type_set.add(group.GetClass()) result += '### %s\n\n' % group.GetType() # Display an image of the frame image_name = group.GetImageName() result += '
\n' image_name = image_path + image_name result += '\n' % (image_name) # check if all outputs are equal for the group: if so, show them # only once all_outputs = {} num_configs = len(group.GetAirframes()) for airframe in group.GetAirframes(): if not self.IsExcluded(airframe, board): for output_name in airframe.GetOutputCodes(): value = airframe.GetOutputValue(output_name) key_value_pair = (output_name, value) if key_value_pair not in all_outputs: all_outputs[key_value_pair] = 0 all_outputs[key_value_pair] += 1 has_common_outputs = any(all_outputs[k] == num_configs for k in all_outputs) if has_common_outputs: outputs_common = ''.join(['
  • {:}: {:}
  • '.format(k[0], k[1]) \ for k in all_outputs if all_outputs[k] == num_configs]) result += '\n' result += ' \n' result += ' \n' result += ' \n' result += ' \n' result += '\n \n\n' % (outputs_common) result += '
    Common Outputs
      %s
    \n' result += '
    \n\n' result += '
    \n' result += '\n' result += ' \n' result += ' \n' result += ' \n' result += '\n' for airframe in group.GetAirframes(): if not self.IsExcluded(airframe, board): name = airframe.GetName() airframe_id = airframe.GetId() airframe_id_entry = '

    SYS_AUTOSTART = %s

    ' % (airframe_id) maintainer = airframe.GetMaintainer() maintainer_entry = '' if maintainer != '': maintainer_entry = 'Maintainer: %s' % (html.escape(maintainer)) url = airframe.GetFieldValue('url') name_anchor='%s_%s_%s' % (group.GetClass(),group.GetType(),name) name_anchor=name_anchor.replace(' ','_').lower() name_anchor=name_anchor.replace('"','_').lower() name_anchor='id="%s"' % name_anchor name_entry = name if url != '': name_entry = '%s' % (url, name) outputs = '' if has_outputs: outputs_entry = '

    Specific Outputs:' + outputs + '

    ' else: outputs_entry = '' result += ('\n \n \n\n' % (name_anchor, name_entry, maintainer_entry, airframe_id_entry, outputs_entry)) #Close the table. result += '\n
    Name
    %s%s%s%s
    \n
    \n\n' self.output = result def IsExcluded(self, airframe, board): for code in airframe.GetArchCodes(): if "CONFIG_ARCH_BOARD_{0}".format(code) == board and airframe.GetArchValue(code) == "exclude": return True return False def Save(self, filename): with codecs.open(filename, 'w', 'utf-8') as f: f.write(self.output)