Esempio n. 1
0
    def test_xml_parser_primary_repo02(self):

        userdata = {
                "pkgs": [],
                "pkgcb_calls": 0,
                "warnings": []
            }

        def newpkgcb(pkgId, name, arch):
            pkg = cr.Package()
            userdata["pkgs"].append(pkg)
            return pkg

        def pkgcb(pkg):
            userdata["pkgcb_calls"] += 1

        def warningcb(warn_type, msg):
            userdata["warnings"].append((warn_type, msg))

        with open(PRIMARY_SNIPPET_02) as primary_snip:
            cr.xml_parse_primary_snippet(primary_snip.read(), newpkgcb, pkgcb, warningcb, 1)

        self.assertEqual([pkg.name for pkg in userdata["pkgs"]],
            ['fake_bash', 'super_kernel'])
        self.assertEqual(userdata["pkgcb_calls"], 2)
        self.assertEqual(userdata["warnings"], [])
Esempio n. 2
0
def parse_repodata(primary_xml, filelists_xml, other_xml):
    """
    Parse repodata to extract package info.
    Args:
        primary_xml (str): a string containing contents of primary.xml
        filelists_xml (str): a string containing contents of filelists.xml
        other_xml (str): a string containing contents of other.xml
    Returns:
        dict: createrepo_c package objects with the pkgId as a key
    """
    package = None

    def pkgcb(pkg):
        """
        A callback which is used when a whole package entry in xml is parsed.
        Args:
            pkg(preaterepo_c.Package): a parsed metadata for a package
        """
        nonlocal package
        package = pkg

    def newpkgcb(pkgId, name, arch):
        """
        A callback which is used when a new package entry is encountered.
        Only opening <package> element is parsed at that moment.
        This function has to return a package which parsed data will be added to
        or None if a package should be skipped.
        pkgId, name and arch of a package can be used to skip further parsing. Available
        only for filelists.xml and other.xml.
        Args:
            pkgId(str): pkgId of a package
            name(str): name of a package
            arch(str): arch of a package
        Returns:
            createrepo_c.Package: a package which parsed data should be added to.
            If None is returned, further parsing of a package will be skipped.
        """
        return package

    # TODO: handle parsing errors/warnings, warningcb callback can be used below
    cr.xml_parse_primary_snippet(primary_xml, pkgcb=pkgcb, do_files=False)
    cr.xml_parse_filelists_snippet(filelists_xml, newpkgcb=newpkgcb)
    cr.xml_parse_other_snippet(other_xml, newpkgcb=newpkgcb)

    changelogs = package.changelogs
    # make sure the changelogs are sorted by date
    changelogs.sort(key=lambda t: t[1])
    # keep only the last 10 changelogs
    package.changelogs = changelogs[-10:]

    return package
Esempio n. 3
0
    def test_xml_parser_primary_snippet01(self):

        userdata = {"pkgs": [], "pkgcb_calls": 0, "warnings": []}

        def newpkgcb(pkgId, name, arch):
            pkg = cr.Package()
            userdata["pkgs"].append(pkg)
            return pkg

        def pkgcb(pkg):
            userdata["pkgcb_calls"] += 1

        def warningcb(warn_type, msg):
            userdata["warnings"].append((warn_type, msg))

        content = open(PRIMARY_SNIPPET_01).read()
        cr.xml_parse_primary_snippet(content, newpkgcb, pkgcb, warningcb, 1)

        self.assertEqual([pkg.name for pkg in userdata["pkgs"]],
                         ['super_kernel'])
        self.assertEqual(userdata["pkgcb_calls"], 1)
        self.assertEqual(userdata["warnings"], [])

        pkg = userdata["pkgs"][0]
        self.assertEqual(
            pkg.pkgId,
            "152824bff2aa6d54f429d43e87a3ff3a0286505c6d93ec87692b5e3a9e3b97bf")
        self.assertEqual(pkg.name, "super_kernel")
        self.assertEqual(pkg.arch, "x86_64")
        self.assertEqual(pkg.version, "6.0.1")
        self.assertEqual(pkg.epoch, "0")
        self.assertEqual(pkg.release, "2")
        self.assertEqual(pkg.summary, "Test package")
        self.assertEqual(
            pkg.description,
            "This package has provides, requires, obsoletes, conflicts options."
        )
        self.assertEqual(
            pkg.url,
            "http://so_super_kernel.com/it_is_awesome/yep_it_really_is")
        self.assertEqual(pkg.time_file, 1334667003)
        self.assertEqual(pkg.time_build, 1334667003)
        self.assertEqual(pkg.rpm_license, "LGPLv2")
        self.assertEqual(pkg.rpm_vendor, None)
        self.assertEqual(pkg.rpm_group, "Applications/System")
        self.assertEqual(pkg.rpm_buildhost, "localhost.localdomain")
        self.assertEqual(pkg.rpm_sourcerpm, "super_kernel-6.0.1-2.src.rpm")
        self.assertEqual(pkg.rpm_header_start, 280)
        self.assertEqual(pkg.rpm_header_end, 2637)
        self.assertEqual(pkg.rpm_packager, None)
        self.assertEqual(pkg.size_package, 2845)
        self.assertEqual(pkg.size_installed, 0)
        self.assertEqual(pkg.size_archive, 404)
        self.assertEqual(pkg.location_href, "super_kernel-6.0.1-2.x86_64.rpm")
        self.assertEqual(pkg.location_base, None)
        self.assertEqual(pkg.checksum_type, "sha256")
        self.assertEqual(pkg.requires,
                         [('bzip2', 'GE', '0', '1.0.0', None, True),
                          ('expat', None, None, None, None, True),
                          ('glib', 'GE', '0', '2.26.0', None, False),
                          ('zlib', None, None, None, None, False)])
        self.assertEqual(
            pkg.provides,
            [('not_so_super_kernel', 'LT', '0', '5.8.0', None, False),
             ('super_kernel', 'EQ', '0', '6.0.0', None, False),
             ('super_kernel', 'EQ', '0', '6.0.1', '2', False),
             ('super_kernel(x86-64)', 'EQ', '0', '6.0.1', '2', False)])
        self.assertEqual(pkg.conflicts,
                         [('kernel', None, None, None, None, False),
                          ('super_kernel', 'EQ', '0', '5.0.0', None, False),
                          ('super_kernel', 'LT', '0', '4.0.0', None, False)])
        self.assertEqual(pkg.obsoletes,
                         [('kernel', None, None, None, None, False),
                          ('super_kernel', 'EQ', '0', '5.9.0', None, False)])
        self.assertEqual(pkg.files, [(None, '/usr/bin/', 'super_kernel')])
        self.assertEqual(pkg.changelogs, [])