def load_xmls()

in tools/manifest_tools/manifest_common.py [0:0]


def load_xmls (config_filename, max_num_xmls, xml_type):
    """
    Load XMLs listed in config file

    :param config_filename: Path to config file
    :param max_num_xmls: Maximum number of XMLs that can be loaded, set to None if no limit
    :param xml_type: Type of XML

    :return list of XML elements, boolean indicating whether to sign output or not, key size,
        key to use for signing, output ID, output filename and manifest xml version, boolean for
        whether XML is for an empty manifest, number of non-contiguous RW sections supported,
        selection list, component type to ID map, component map file
    """

    config = load_config (config_filename)
    key_size = None
    prv_key_path = None
    key_type = 0
    hash_type = None
    sign = False
    empty = False
    max_rw_sections = 3
    selection_list = None
    component_map = None
    component_map_file = ""

    if "key_type" in config and config["key_type"]:
        if config["key_type"] == "ECC":
            key_type = 1

    if "hash_type" in config and config["hash_type"]:
        if config["hash_type"] == "SHA512":
            hash_type = 2
        elif config["hash_type"] == "SHA384":
            hash_type = 1
        else:
            hash_type = 0

    if "key_size" in config and config["key_size"]:
        key_size = int (config["key_size"])

    if "prv_key_path" in config and config["prv_key_path"]:
        prv_key_path = config["prv_key_path"]

    if "max_rw_sections" in config and config["max_rw_sections"]:
        max_rw_sections = int (config["max_rw_sections"])

        if max_rw_sections > 6:
            raise RuntimeError ("Maximum RW sections cannot be greater than 6")

    if "cfm" in config and config["cfm"]:
        selection_list = manifest_parser.load_and_process_selection_xml (config["cfm"])
    elif xml_type is manifest_types.CFM:
        raise RuntimeError ("Missing CFM XML")

    if "component_map" in config and config["component_map"]:
        component_map_file = config["component_map"]
        component_map = load_component_map (component_map_file)

    if max_num_xmls and (len (config["xml_list"]) > max_num_xmls):
        raise RuntimeError ("Too many XML files provided: {0}".format (len (config["xml_list"])))

    sign, key_size, key = load_key (key_type, key_size, prv_key_path)

    processed_xml = {}
    xml_version = None
    matching_xml_found = False

    for xml in config["xml_list"]:
        parsed_xml, curr_xml_version, empty = manifest_parser.load_and_process_xml (xml, xml_type,
            selection_list)

        if parsed_xml is None:
            continue

        if xml_version is None:
            xml_version = curr_xml_version

        if xml_version != curr_xml_version:
            raise RuntimeError (
                "Failed to generate manifest: XML version is different - {0}".format (xml))

        for previous_file, previous_xml in processed_xml.items():
            if ((xml_type == manifest_types.PFM) and \
                (previous_xml.get('version_id') == parsed_xml.get('version_id'))):
                if (previous_xml == parsed_xml):
                    matching_xml_found = True
                    break
                else:
                    raise RuntimeError (
                        "Failed to generate manifest: XML files {0} and {1} have same version " \
                        "string {2}, but different data".format (previous_file, xml, previous_xml.get ('version_id')))

        if matching_xml_found:
            matching_xml_found = False
            continue

        processed_xml.update ({xml:parsed_xml})

    if "id" in config:
        manifest_id = config["id"]
    else:
        manifest_id = list (processed_xml.items())[0][1]["version"]

    if len (processed_xml) == 0:
        empty = True

    return processed_xml, sign, key_size, key, key_type, hash_type, manifest_id, config["output"], \
        xml_version, empty, max_rw_sections, selection_list, component_map, component_map_file