Exemplo n.º 1
0
def extract(path: str) -> ExtractedMetadata:
    if not path.endswith('.metainfo.xml'):
        raise _errors.UnhandledFileError(path, 'appstream')

    try:
        tree = ElementTree().parse(path)
    except ParseError as e:
        raise _errors.AppstreamFileParseError(path) from e

    summary = None
    node = tree.find('summary')
    if node is not None:
        summary = node.text

    description = None
    node = tree.find('description')
    if node is not None:
        description = node.text

    return ExtractedMetadata(summary=summary, description=description)
Exemplo n.º 2
0
def extract(path: str) -> ExtractedMetadata:
    if (not path.endswith('.metainfo.xml')
            and not path.endswith('.appdata.xml')):
        raise _errors.UnhandledFileError(path, 'appstream')

    try:
        tree = ElementTree().parse(path)
    except ParseError as e:
        raise _errors.AppstreamFileParseError(path) from e

    summary = None
    node = tree.find('summary')
    if node is not None:
        summary = node.text.strip()

    description = None
    node = tree.find('description')
    if node is not None:
        description = node.text.strip()

    icon = None
    node = tree.find('icon')
    if (node is not None and 'type' in node.attrib
            and node.attrib['type'] == 'local'):
        # TODO Currently we only support local icons.
        # See bug https://bugs.launchpad.net/snapcraft/+bug/1742348
        # for supporting remote icons.
        # --elopio -20180109
        icon = node.text.strip()

    desktop_file_ids = []
    nodes = tree.findall('launchable')
    for node in nodes:
        if ('type' in node.attrib and node.attrib['type'] == 'desktop-id'):
            desktop_file_ids.append(node.text.strip())

    return ExtractedMetadata(summary=summary,
                             description=description,
                             icon=icon,
                             desktop_file_ids=desktop_file_ids)
Exemplo n.º 3
0
def extract(path: str) -> ExtractedMetadata:
    if not path.endswith(".metainfo.xml") and not path.endswith(".appdata.xml"):
        raise _errors.UnhandledFileError(path, "appstream")

    try:
        tree = ElementTree().parse(path)
    except ParseError as e:
        raise _errors.AppstreamFileParseError(path) from e

    common_id = _get_value_from_xml_element(tree, "id")
    summary = _get_value_from_xml_element(tree, "summary")
    description = _get_value_from_xml_element(tree, "description")

    icon = None
    node = tree.find("icon")
    if node is not None and "type" in node.attrib and node.attrib["type"] == "local":
        # TODO Currently we only support local icons.
        # See bug https://bugs.launchpad.net/snapcraft/+bug/1742348
        # for supporting remote icons.
        # --elopio -20180109
        icon = node.text.strip()

    desktop_file_paths = []
    nodes = tree.findall("launchable")
    for node in nodes:
        if "type" in node.attrib and node.attrib["type"] == "desktop-id":
            desktop_file_id = node.text.strip()
            desktop_file_path = _desktop_file_id_to_path(desktop_file_id)
            if desktop_file_path:
                desktop_file_paths.append(desktop_file_path)

    return ExtractedMetadata(
        common_id=common_id,
        summary=summary,
        description=description,
        icon=icon,
        desktop_file_paths=desktop_file_paths,
    )
Exemplo n.º 4
0
def _get_dom(path: str) -> lxml.etree.ElementTree:
    try:
        return lxml.etree.parse(path)
    except lxml.etree.ParseError as e:
        raise _errors.AppstreamFileParseError(path) from e