def reorganize_airframe_xml(airframe_xml):
    airframe = ET.fromstring("<!DOCTYPE airframe SYSTEM \"airframe.dtd\"><!-- \n\tAirframe comment \n--> <airframe/>")
    child1 = ET.Comment("+-+-+-+-+-+-+- FIRMWARES -+-+-+-+-+-+-+")
    airframe.append(child1)

    find_and_add(airframe_xml, airframe, "firmware")

    airframe.append(ET.Comment("+-+-+-+-+-+-+-  MODULES  -+-+-+-+-+-+-+"))
    find_and_add(airframe_xml, airframe, "modules")

    airframe.append(ET.Comment("+-+-+-+-+-+-+- ACTUATORS -+-+-+-+-+-+-+"))
    find_and_add(airframe_xml, airframe, "servos")
    find_and_add(airframe_xml, airframe, "commands")
    find_and_add(airframe_xml, airframe, "rc_commands")
    find_and_add_sections_with_name(airframe_xml,airframe,"SERVO_MIXER_GAINS")
    find_and_add(airframe_xml, airframe, "command_laws")
    find_and_add_sections_with_name(airframe_xml,airframe,"FAILSAFE")

    airframe.append(ET.Comment("+-+-+-+-+-+-+-  SENSORS  -+-+-+-+-+-+-+"))
    find_and_add_sections_with_name(airframe_xml,airframe,"ADC")
    find_and_add_sections_with_name(airframe_xml,airframe,"INS")
    find_and_add_sections_with_name(airframe_xml,airframe,"AHRS")
    find_and_add_sections_with_name(airframe_xml,airframe,"XSENS")

    airframe.append(ET.Comment("+-+-+-+-+-+-+-   GAINS   -+-+-+-+-+-+-+"))
    find_and_add_sections_with_name(airframe_xml,airframe,"HORIZONTAL CONTROL")
    find_and_add_sections_with_name(airframe_xml,airframe,"VERTICAL CONTROL")
    find_and_add_sections_with_name(airframe_xml,airframe,"AGGRESSIVE")


    airframe.append(ET.Comment("+-+-+-+-+-+-+-   MISC    -+-+-+-+-+-+-+"))

    for block in airframe_xml.getroot():
        name = block.get("name")
        if name == None:
            name = "None"
        if (block.tag == "firmware"):
            print("firmware",block.tag, name)
        elif (block.tag in ["servos", "commands", "rc_commands", "command_laws"]):
            print("actuator",block.tag, name)
        else:
            print("other",block.tag, name)
            airframe.append(block)


    xml_common.indent(airframe)
    #print(etree.tostring(airframe))
    ET.ElementTree(airframe).write('test.xml',pretty_print=True)
Exemple #2
0
def reorganize_airframe_xml(airframe_xml):
    some_file_like_object = StringIO(u"<airframe/>")
    airframe_xml_tree = ET.parse(some_file_like_object)
    airframe = airframe_xml_tree.getroot()

    if 'name' not in airframe_xml.getroot().attrib:
        print("Airframe has no name!")
    else:
        airframe.set('name', airframe_xml.getroot().get('name'))

    find_and_add(airframe_xml, airframe, "description")

    find_or_add_group(airframe_xml, airframe, "FIRMWARE")
    find_and_add(airframe_xml, airframe, "firmware")
    find_and_add_sections_with_name(airframe_xml, airframe, "AUTOPILOT")

    find_or_add_group(airframe_xml, airframe, "MODULES")
    find_and_add(airframe_xml, airframe, "modules")

    find_or_add_group(airframe_xml, airframe, "ACTUATORS")
    find_and_add_sections_with_name(airframe_xml, airframe, "ACTUATORS_MKK")
    find_and_add_sections_with_name(airframe_xml, airframe, "ACTUATORS_MKK_V2")
    find_and_add(airframe_xml, airframe, "servos")
    find_and_add(airframe_xml, airframe, "commands")
    find_and_add(airframe_xml, airframe, "ap_only_commands")
    find_and_add(airframe_xml, airframe, "rc_commands")
    find_and_add_sections_with_name(airframe_xml, airframe, "AUTO1")
    find_and_add_sections_with_name(airframe_xml, airframe,
                                    "SERVO_MIXER_GAINS")
    find_and_add_sections_with_name(airframe_xml, airframe, "MIXER")
    find_and_add_sections_with_name(airframe_xml, airframe, "MIXING")
    find_and_add(airframe_xml, airframe, "command_laws")
    find_and_add_sections_with_name(airframe_xml, airframe, "TRIM")
    find_and_add_sections_with_name(airframe_xml, airframe, "FAILSAFE")

    find_or_add_group(airframe_xml, airframe, "SENSORS")
    find_and_add_sections_with_name(airframe_xml, airframe, "ADC")
    find_and_add_sections_with_name(airframe_xml, airframe, "INFRARED")
    find_and_add_sections_with_name(airframe_xml, airframe, "IMU")
    find_and_add_sections_with_name(airframe_xml, airframe, "AHRS")
    find_and_add_sections_with_name(airframe_xml, airframe, "INS")
    find_and_add_sections_with_name(airframe_xml, airframe, "XSENS")

    find_or_add_group(airframe_xml, airframe, "GAINS")
    # Fixedwing
    find_and_add_sections_with_name(airframe_xml, airframe,
                                    "HORIZONTAL CONTROL")
    find_and_add_sections_with_name(airframe_xml, airframe, "VERTICAL CONTROL")
    find_and_add_sections_with_name(airframe_xml, airframe, "AGGRESSIVE")
    # Rotorcraft
    find_and_add_sections_with_name(airframe_xml, airframe,
                                    "STABILIZATION_RATE")
    find_and_add_sections_with_name(airframe_xml, airframe,
                                    "STABILIZATION_ATTITUDE")
    find_and_add_sections_with_name(airframe_xml, airframe, "GUIDANCE_V")
    find_and_add_sections_with_name(airframe_xml, airframe, "GUIDANCE_H")

    find_or_add_group(airframe_xml, airframe, "MISC")

    find_and_add(airframe_xml, airframe, "*")

    xml_common.indent(airframe)

    temp = airframe.findall("./*")
    for t in temp:
        t.tail = "\n\n  "

    #print(etree.tostring(airframe))
    #ET.ElementTree(airframe_xml_tree).write('test.xml')
    return airframe_xml_tree
Exemple #3
0
def find_and_add_sections_with_name(source, target, find_name):
    temp = source.getroot().findall("./*[@name='" + find_name + "']")
    for t in temp:
        xml_common.indent(t, 1)
    target.extend(temp)
Exemple #4
0
def find_and_add(source, target, search):
    temp = source.getroot().findall("./" + search)
    for t in temp:
        xml_common.indent(t, 1)
    target.extend(temp)
    find_or_add_group(airframe_xml, airframe, "GAINS")
    # Fixedwing
    find_and_add_sections_with_name(airframe_xml, airframe, "HORIZONTAL CONTROL")
    find_and_add_sections_with_name(airframe_xml, airframe, "VERTICAL CONTROL")
    find_and_add_sections_with_name(airframe_xml, airframe, "AGGRESSIVE")
    # Rotorcraft
    find_and_add_sections_with_name(airframe_xml, airframe, "STABILIZATION_RATE")
    find_and_add_sections_with_name(airframe_xml, airframe, "STABILIZATION_ATTITUDE")
    find_and_add_sections_with_name(airframe_xml, airframe, "GUIDANCE_V")
    find_and_add_sections_with_name(airframe_xml, airframe, "GUIDANCE_H")

    find_or_add_group(airframe_xml, airframe, "MISC")

    find_and_add(airframe_xml, airframe, "*")

    xml_common.indent(airframe)

    temp = airframe.findall("./*")
    for t in temp:
        t.tail = "\n\n  "

    #print(etree.tostring(airframe))
    #ET.ElementTree(airframe_xml_tree).write('test.xml')
    return airframe_xml_tree


def get_airframe_header(airframe_file):
    try:
        with open(airframe_file) as inputFileHandle:
            fullfile = inputFileHandle.read()
            pos = fullfile.find("<airframe")
Exemple #6
0
def reorganize_airframe_xml(airframe_xml):
    some_file_like_object = StringIO.StringIO("<airframe/>")
    airframe_xml_tree = ET.parse(some_file_like_object)
    airframe = airframe_xml_tree.getroot()

    if 'name' not in airframe_xml.getroot().attrib:
        print("Airframe has no name!")
    else:
        airframe.set('name', airframe_xml.getroot().get('name'))

    find_or_add_group(airframe_xml, airframe, "FIRMWARE")
    find_and_add(airframe_xml, airframe, "firmware")
    find_and_add_sections_with_name(airframe_xml, airframe, "AUTOPILOT")

    find_or_add_group(airframe_xml, airframe, "MODULES")
    find_and_add(airframe_xml, airframe, "modules")

    find_or_add_group(airframe_xml, airframe, "ACTUATORS")
    find_and_add_sections_with_name(airframe_xml, airframe, "ACTUATORS_MKK")
    find_and_add_sections_with_name(airframe_xml, airframe, "ACTUATORS_MKK_V2")
    find_and_add(airframe_xml, airframe, "servos")
    find_and_add(airframe_xml, airframe, "commands")
    find_and_add(airframe_xml, airframe, "ap_only_commands")
    find_and_add(airframe_xml, airframe, "rc_commands")
    find_and_add_sections_with_name(airframe_xml, airframe, "AUTO1")
    find_and_add_sections_with_name(airframe_xml, airframe, "SERVO_MIXER_GAINS")
    find_and_add_sections_with_name(airframe_xml, airframe, "MIXER")
    find_and_add_sections_with_name(airframe_xml, airframe, "MIXING")
    find_and_add(airframe_xml, airframe, "command_laws")
    find_and_add_sections_with_name(airframe_xml, airframe, "TRIM")
    find_and_add_sections_with_name(airframe_xml, airframe, "FAILSAFE")

    find_or_add_group(airframe_xml, airframe, "SENSORS")
    find_and_add_sections_with_name(airframe_xml, airframe, "ADC")
    find_and_add_sections_with_name(airframe_xml, airframe, "INFRARED")
    find_and_add_sections_with_name(airframe_xml, airframe, "IMU")
    find_and_add_sections_with_name(airframe_xml, airframe, "AHRS")
    find_and_add_sections_with_name(airframe_xml, airframe, "INS")
    find_and_add_sections_with_name(airframe_xml, airframe, "XSENS")

    find_or_add_group(airframe_xml, airframe, "GAINS")
    # Fixedwing
    find_and_add_sections_with_name(airframe_xml, airframe, "HORIZONTAL CONTROL")
    find_and_add_sections_with_name(airframe_xml, airframe, "VERTICAL CONTROL")
    find_and_add_sections_with_name(airframe_xml, airframe, "AGGRESSIVE")
    # Rotorcraft
    find_and_add_sections_with_name(airframe_xml, airframe, "STABILIZATION_RATE")
    find_and_add_sections_with_name(airframe_xml, airframe, "STABILIZATION_ATTITUDE")
    find_and_add_sections_with_name(airframe_xml, airframe, "GUIDANCE_V")
    find_and_add_sections_with_name(airframe_xml, airframe, "GUIDANCE_H")

    find_or_add_group(airframe_xml, airframe, "MISC")

    find_and_add(airframe_xml, airframe, "*")

    xml_common.indent(airframe)

    temp = airframe.findall("./*")
    for t in temp:
        t.tail = "\n\n  "

    #print(etree.tostring(airframe))
    #ET.ElementTree(airframe_xml_tree).write('test.xml')
    return airframe_xml_tree
Exemple #7
0
def find_and_add_sections_with_name(source, target, find_name):
    temp = source.getroot().findall("./*[@name='" + find_name + "']")
    for t in temp:
        xml_common.indent(t, 1)
    target.extend(temp)
Exemple #8
0
def find_and_add(source, target, search):
    temp = source.getroot().findall("./" + search)
    for t in temp:
        xml_common.indent(t, 1)
    target.extend(temp)