예제 #1
0
def primarymetadata_from_xml_factory(xmlpath, archpath):
    pri_obj = PrimaryMetadata(xmlpath, archpath)
    for _, elements in etree.iterparse(xmlpath, tag="%spackage" % PRI_NS):
        elements = MyElement(elements)
        pp = PrimaryPackage()
        for elem in elements:
            elem = MyElement(elem)
            if elem.tag.endswith("name"):
                pp.name = elem.text
            elif elem.tag.endswith("arch"):
                pp.arch = elem.text
            elif elem.tag.endswith("version"):
                pp.epoch = elem.get("epoch")
                pp.version = elem.get("ver")
                pp.release = elem.get("rel")
            elif elem.tag.endswith("checksum"):
                pp.checksum_type = elem.get("type")
                pp.checksum = elem.text
            elif elem.tag.endswith("summary"):
                pp.summary = elem.text
            elif elem.tag.endswith("description"):
                pp.description = elem.text
            elif elem.tag.endswith("packager"):
                pp.packager = elem.text
            elif elem.tag.endswith("url"):
                pp.url = elem.text
            elif elem.tag.endswith("time"):
                pp.time_file = int(elem.get("file"))
                pp.time_build = int(elem.get("build"))
            elif elem.tag.endswith("size"):
                pp.size_package = int(elem.get("package"))
                pp.size_installed = int(elem.get("installed"))
                pp.size_archive = int(elem.get("archive"))
            elif elem.tag.endswith("location"):
                pp.location = elem.get("href")
                pp.location_base = elem.get("{http://www.w3.org/XML/1998/namespace}base")
            elif elem.tag.endswith("format"):
                for felem in elem:
                    if felem.tag.endswith("license"):
                        pp.license = felem.text
                    elif felem.tag.endswith("vendor"):
                        pp.vendor = felem.text
                    elif felem.tag.endswith("group"):
                        pp.group = felem.text
                    elif felem.tag.endswith("buildhost"):
                        pp.buildhost = felem.text
                    elif felem.tag.endswith("sourcerpm"):
                        pp.sourcerpm = felem.text
                    elif felem.tag.endswith("header-range"):
                        pp.header_start = int(felem.get("start"))
                        pp.header_end = int(felem.get("end"))
                    elif felem.tag.endswith("provides"):
                        pp.provides = _parse_pco(felem)
                    elif felem.tag.endswith("conflicts"):
                        pp.conflicts = _parse_pco(felem)
                    elif felem.tag.endswith("obsoletes"):
                        pp.obsoletes = _parse_pco(felem)
                    elif felem.tag.endswith("requires"):
                        pp.requires = _parse_pco(felem, requires=True)
                    elif felem.tag.endswith("file"):
                        if felem.get("type") == "dir":
                            pp.dirs.add(felem.text)
                        elif felem.get("type") == "ghost":
                            pp.ghosts.add(felem.text)
                        else:
                            pp.files.add(felem.text)
        elements.clear()
        pri_obj.append(pp.checksum, pp)
    return pri_obj
예제 #2
0
def primarymetadata_from_xml_factory(xmlpath, archpath):
    pri_obj = PrimaryMetadata(xmlpath, archpath)
    for _, elements in etree.iterparse(xmlpath, tag="%spackage" % PRI_NS):
        elements = MyElement(elements)
        pp = PrimaryPackage()
        for elem in elements:
            elem = MyElement(elem)
            if elem.tag.endswith("name"):
                pp.name = elem.text
            elif elem.tag.endswith("arch"):
                pp.arch = elem.text
            elif elem.tag.endswith("version"):
                pp.epoch = elem.get("epoch")
                pp.version = elem.get("ver")
                pp.release = elem.get("rel")
            elif elem.tag.endswith("checksum"):
                pp.checksum_type = elem.get("type")
                pp.checksum = elem.text
            elif elem.tag.endswith("summary"):
                pp.summary = elem.text
            elif elem.tag.endswith("description"):
                pp.description = elem.text
            elif elem.tag.endswith("packager"):
                pp.packager = elem.text
            elif elem.tag.endswith("url"):
                pp.url = elem.text
            elif elem.tag.endswith("time"):
                pp.time_file = int(elem.get("file"))
                pp.time_build = int(elem.get("build"))
            elif elem.tag.endswith("size"):
                pp.size_package = int(elem.get("package"))
                pp.size_installed = int(elem.get("installed"))
                pp.size_archive = int(elem.get("archive"))
            elif elem.tag.endswith("location"):
                pp.location = elem.get("href")
                pp.location_base = elem.get(
                    "{http://www.w3.org/XML/1998/namespace}base")
            elif elem.tag.endswith("format"):
                for felem in elem:
                    if felem.tag.endswith("license"):
                        pp.license = felem.text
                    elif felem.tag.endswith("vendor"):
                        pp.vendor = felem.text
                    elif felem.tag.endswith("group"):
                        pp.group = felem.text
                    elif felem.tag.endswith("buildhost"):
                        pp.buildhost = felem.text
                    elif felem.tag.endswith("sourcerpm"):
                        pp.sourcerpm = felem.text
                    elif felem.tag.endswith("header-range"):
                        pp.header_start = int(felem.get("start"))
                        pp.header_end = int(felem.get("end"))
                    elif felem.tag.endswith("provides"):
                        pp.provides = _parse_pco(felem)
                    elif felem.tag.endswith("conflicts"):
                        pp.conflicts = _parse_pco(felem)
                    elif felem.tag.endswith("obsoletes"):
                        pp.obsoletes = _parse_pco(felem)
                    elif felem.tag.endswith("requires"):
                        pp.requires = _parse_pco(felem, requires=True)
                    elif felem.tag.endswith("file"):
                        if felem.get("type") == "dir":
                            pp.dirs.add(felem.text)
                        elif felem.get("type") == "ghost":
                            pp.ghosts.add(felem.text)
                        else:
                            pp.files.add(felem.text)
        elements.clear()
        pri_obj.append(pp.checksum, pp)
    return pri_obj