from xml.sax.saxutils import escape import codecs import os class MarkdownTablesOutput(): def __init__(self, groups, board, image_path): result = ("# Airframes Reference\n" "> **Note** **This list is auto-generated from the source code**.\n" "> \n" "> The **AUX** channels are only available on Pixhawk Boards (labeled with **AUX OUT**).\n" "> \n" "\n") result += """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.\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.GetName() # 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 outputs_prev = ['', ''] # split into MAINx and others (AUXx) outputs_match = [True, True] for param in group.GetParams(): if not self.IsExcluded(param, board): outputs_current = ['', ''] for output_name in param.GetOutputCodes(): value = param.GetOutputValue(output_name) if output_name.lower().startswith('main'): idx = 0 else: idx = 1 outputs_current[idx] += '
  • %s: %s
  • ' % (output_name, value) for i in range(2): if len(outputs_current[i]) != 0: if outputs_prev[i] == '': outputs_prev[i] = outputs_current[i] elif outputs_current[i] != outputs_prev[i]: outputs_match[i] = False for i in range(2): if len(outputs_prev[i]) == 0: outputs_match[i] = False if not outputs_match[i]: outputs_prev[i] = '' if outputs_match[0] or outputs_match[1]: result += '\n' result += ' \n' result += ' \n' result += ' \n' result += ' \n' result += '\n' result += '\n \n\n' % (outputs_prev[0], outputs_prev[1]) result += '
    Common Outputs
      %s%s
    \n' result += '
    \n\n' result += '\n' result += ' \n' result += ' \n' result += ' \n' result += ' \n' result += '\n' for param in group.GetParams(): if not self.IsExcluded(param, board): #print("generating: {0} {1}".format(param.GetName(), excluded)) name = param.GetName() airframe_id = param.GetId() airframe_id_entry = '

    SYS_AUTOSTART = %s

    ' % (airframe_id) maintainer = param.GetMaintainer() maintainer_entry = '' if maintainer != '': maintainer_entry = '

    Maintainer: %s

    ' % (maintainer) url = param.GetFieldValue('url') name_anchor='id="%s_%s_%s"' % (group.GetClass(),group.GetName(),name) name_anchor=name_anchor.replace(' ','_').lower() 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\n' % (name_anchor, name_entry, maintainer_entry, airframe_id_entry, outputs_entry)) #Close the table. result += '
    Name
    %s%s%s%s
    \n\n' self.output = result def IsExcluded(self, param, board): for code in param.GetArchCodes(): if "CONFIG_ARCH_BOARD_{0}".format(code) == board and param.GetArchValue(code) == "exclude": return True return False def Save(self, filename): with codecs.open(filename, 'w', 'utf-8') as f: f.write(self.output)