コード例 #1
0
def main():
    """
    Main program entry point
    """
    parser = argparse.ArgumentParser(description="Create version header")
    parser.add_argument(
        "output",
        nargs="?",
        type=argparse.FileType("w"),
        default=sys.stdout,
        help="Path to write version header into",
    )
    parser.add_argument(
        "--check",
        action="store_true",
        default=False,
        help="Check framework and fallback version",
    )
    args = parser.parse_args()

    # Build the version output
    fprime_version = get_fprime_version()
    project_version = get_project_version()
    create_version_file(args.output, fprime_version, project_version)

    # Check version if asked to do so
    if args.check and not fprime_version.startswith(FALLBACK_VERSION):
        expected = fprime_version[: len(FALLBACK_VERSION)]
        print(
            f"[ERROR] Fallback version { FALLBACK_VERSION } not updated. Expected { expected }.",
            file=sys.stderr,
        )
        sys.exit(2)
    sys.exit(0)
コード例 #2
0
ファイル: gds_dictgen.py プロジェクト: nasa/fprime
def generate_xml_dict(the_parsed_topology_xml, xml_filename, opt):
    """
    Generates GDS XML dictionary from parsed topology XML
    """
    if VERBOSE:
        print("Topology xml type description file: %s" % xml_filename)
    model = TopoFactory.TopoFactory.getInstance()
    topology_model = model.create(the_parsed_topology_xml)

    GenFactory.GenFactory.getInstance()

    # uses the topology model to process the items
    # create list of used parsed component xmls
    parsed_xml_dict = {}
    for comp in the_parsed_topology_xml.get_instances():
        if comp.get_type() in topology_model.get_base_id_dict():
            parsed_xml_dict[comp.get_type()] = comp.get_comp_xml()
        else:
            PRINT.info(
                "Components with type {} aren't in the topology model.".format(
                    comp.get_type()))

    #
    xml_list = []
    for parsed_xml_type in parsed_xml_dict:
        if parsed_xml_dict[parsed_xml_type] is None:
            print(
                "ERROR: XML of type {} is being used, but has not been parsed correctly. Check if file exists or add xml file with the 'import_component_type' tag to the Topology file."
                .format(parsed_xml_type))
            raise Exception()
        xml_list.append(parsed_xml_dict[parsed_xml_type])

    topology_model.set_instance_xml_list(xml_list)

    topology_dict = etree.Element("dictionary")
    topology_dict.attrib["topology"] = the_parsed_topology_xml.get_name()
    topology_dict.attrib["framework_version"] = get_fprime_version()

    top_dict_gen = TopDictGenerator.TopDictGenerator(
        parsed_xml_dict, print if VERBOSE else lambda _: None)
    for comp in the_parsed_topology_xml.get_instances():
        comp_type = comp.get_type()
        comp_name = comp.get_name()
        comp_id = int(comp.get_base_id())
        PRINT.debug("Processing {} [{}] ({})".format(comp_name, comp_type,
                                                     hex(comp_id)))

        top_dict_gen.set_current_comp(comp)

        top_dict_gen.check_for_serial_xml()
        top_dict_gen.check_for_commands()
        top_dict_gen.check_for_channels()
        top_dict_gen.check_for_events()
        top_dict_gen.check_for_parameters()

    top_dict_gen.remove_duplicate_enums()

    topology_dict.append(top_dict_gen.get_enum_list())
    topology_dict.append(top_dict_gen.get_serializable_list())
    topology_dict.append(top_dict_gen.get_command_list())
    topology_dict.append(top_dict_gen.get_event_list())
    topology_dict.append(top_dict_gen.get_telemetry_list())
    topology_dict.append(top_dict_gen.get_parameter_list())

    fileName = the_parsed_topology_xml.get_xml_filename().replace(
        "Ai.xml", "Dictionary.xml")
    if VERBOSE:
        print("Generating XML dictionary %s" % fileName)
    fd = open(
        fileName,
        "wb")  # Note: binary forces the same encoding of the source files
    fd.write(etree.tostring(topology_dict, pretty_print=True))
    if VERBOSE:
        print("Generated XML dictionary %s" % fileName)

    return topology_model
コード例 #3
0
def generate_topology(the_parsed_topology_xml, xml_filename, opt):
    DEBUG.debug(f"Topology xml type description file: {xml_filename}")
    generator = TopoFactory.TopoFactory.getInstance()
    if not (opt.default_topology_dict or opt.xml_topology_dict):
        generator.set_generate_ID(False)
    topology_model = generator.create(the_parsed_topology_xml)

    if opt.is_ptr:
        PRINT.info("Topology Components will be initialized as Pointers. ")
        topology_model.is_ptr = opt.is_ptr
    if opt.connect_only:
        PRINT.info("Only port connections will be generated for Topology.")
        topology_model.connect_only = opt.connect_only

    generator = GenFactory.GenFactory.getInstance()

    if "Ai" in xml_filename:
        base = xml_filename.split("Ai")[0]
        h_instance_name = base + "_H"
        cpp_instance_name = base + "_Cpp"
        csv_instance_name = base + "_ID"
        cmd_html_instance_name = base + "_Cmd_HTML"
        channel_html_instance_name = base + "_Channel_HTML"
        event_html_instance_name = base + "_Event_HTML"
    else:
        PRINT.info("Missing Ai at end of file name...")
        raise OSError

    # Figures out what visitor to use
    if opt.default_topology_dict or opt.xml_topology_dict:
        generator.configureVisitor(h_instance_name, "InstanceTopologyHVisitor",
                                   True, True)
        generator.configureVisitor(cpp_instance_name,
                                   "InstanceTopologyCppVisitor", True, True)
    else:
        generator.configureVisitor(h_instance_name, "TopologyHVisitor", True,
                                   True)
        generator.configureVisitor(cpp_instance_name, "TopologyCppVisitor",
                                   True, True)

    # Used to generate base ID/base ID window CSV files
    generator.configureVisitor(csv_instance_name, "TopologyIDVisitor", True,
                               True)

    # Used to generate HTML tables of ID's etc.
    if opt.default_topology_dict or opt.xml_topology_dict:
        generator.configureVisitor(cmd_html_instance_name,
                                   "InstanceTopologyCmdHTMLVisitor", True,
                                   True)
        generator.configureVisitor(channel_html_instance_name,
                                   "InstanceTopologyChannelsTMLVisitor", True,
                                   True)
        generator.configureVisitor(event_html_instance_name,
                                   "InstanceTopologyEventsHTMLVisitor", True,
                                   True)

    # uses the topology model to process the items
    if opt.default_topology_dict or opt.xml_topology_dict:
        # create list of used parsed component xmls
        parsed_xml_dict = {}
        for comp in the_parsed_topology_xml.get_instances():
            if comp.get_type() in topology_model.get_base_id_dict():
                parsed_xml_dict[comp.get_type()] = comp.get_comp_xml()
                # comp.set_component_object(comp.)
            else:
                PRINT.info(
                    f"Components with type {comp.get_type()} aren't in the topology model."
                )

        # Hack to set up deployment path for instanced dictionaries (if one exists remove old one)
        #
        if opt.default_topology_dict:
            for build_root in get_build_roots():
                if not os.path.exists(os.path.join(build_root, DEPLOYMENT)):
                    continue
                os.environ["DICT_DIR"] = os.path.join(build_root, DEPLOYMENT,
                                                      "py_dict")
                break
            else:
                raise FileNotFoundError(
                    f"{DEPLOYMENT} not found in any of: {get_build_roots()}")
            dict_dir = os.environ["DICT_DIR"]
            PRINT.info(
                f"Removing old instanced topology dictionaries in: {dict_dir}")
            import shutil

            if os.path.exists(dict_dir):
                shutil.rmtree(dict_dir)
            PRINT.info(
                f"Overriding for instanced topology dictionaries the --dict_dir option with xml derived path: {dict_dir}"
            )
        #
        xml_list = []
        for parsed_xml_type in parsed_xml_dict:
            if parsed_xml_dict[parsed_xml_type] is None:
                PRINT.info(
                    f"XML of type {parsed_xml_type} is being used, but has not been parsed correctly. Check if file exists or add xml file with the 'import_component_type' tag to the Topology file."
                )
                raise Exception()
            xml_list.append(parsed_xml_dict[parsed_xml_type])
            generate_component_instance_dictionary(
                parsed_xml_dict[parsed_xml_type], opt, topology_model)

        topology_model.set_instance_xml_list(xml_list)

        if opt.xml_topology_dict:
            topology_dict = etree.Element("dictionary")
            topology_dict.attrib[
                "topology"] = the_parsed_topology_xml.get_name()
            topology_dict.attrib["framework_version"] = get_fprime_version()

            top_dict_gen = TopDictGenerator.TopDictGenerator(
                parsed_xml_dict, PRINT.debug)
            for comp in the_parsed_topology_xml.get_instances():
                comp_type = comp.get_type()
                comp_name = comp.get_name()
                comp_id = int(comp.get_base_id(), 0)
                PRINT.debug(
                    f"Processing {comp_name} [{comp_type}] ({hex(comp_id)})")

                top_dict_gen.set_current_comp(comp)
                top_dict_gen.check_for_enum_xml()
                top_dict_gen.check_for_serial_xml()
                top_dict_gen.check_for_commands()
                top_dict_gen.check_for_channels()
                top_dict_gen.check_for_events()
                top_dict_gen.check_for_parameters()
                top_dict_gen.check_for_arrays()

            top_dict_gen.remove_duplicate_enums()

            topology_dict.append(top_dict_gen.get_enum_list())
            topology_dict.append(top_dict_gen.get_serializable_list())
            topology_dict.append(top_dict_gen.get_array_list())
            topology_dict.append(top_dict_gen.get_command_list())
            topology_dict.append(top_dict_gen.get_event_list())
            topology_dict.append(top_dict_gen.get_telemetry_list())
            topology_dict.append(top_dict_gen.get_parameter_list())

            fileName = the_parsed_topology_xml.get_xml_filename().replace(
                "Ai.xml", "Dictionary.xml")
            PRINT.info(f"Generating XML dictionary {fileName}")
            fd = open(
                fileName, "wb"
            )  # Note: binary forces the same encoding of the source files
            fd.write(etree.tostring(topology_dict, pretty_print=True))

    initFiles = generator.create("initFiles")
    # startSource = generator.create("startSource")
    includes1 = generator.create("includes1")
    # includes2   = generator.create("includes2")
    # namespace   = generator.create("namespace")
    public = generator.create("public")
    finishSource = generator.create("finishSource")
    #
    # Generate the source code products here.
    #
    # 1. Open all the files
    initFiles(topology_model)
    #
    # 2. Generate includes and static code here.
    includes1(topology_model)
    #
    # 3. Generate public function to instance components and connect them here.
    public(topology_model)
    #
    # 4. Generate final code here and close all files.
    finishSource(topology_model)

    return topology_model