Example #1
0
    def iter_parse(self, path: str, factory: PackageFactory) -> Iterable[PackageMaker]:
        licenses: dict[str, str] = {}
        packages: dict[str, PackageData] = {}

        for entry in iter_xml_elements_at_level(path, 1, ['license', 'package', 'version']):
            if entry.tag == 'license':
                licenses[safe_getattr(entry, 'name')] = safe_findtext(entry, 'title')
            elif entry.tag == 'package':
                packages[safe_getattr(entry, 'name')] = PackageData(
                    safe_findtext(entry, 'title'),
                    safe_findalltexts(entry, 'license'),
                    safe_findalltexts(entry, 'category'),
                    safe_findalltexts(entry, 'url'),
                )
            elif entry.tag == 'version':
                pkgname = safe_getattr(entry, 'package')
                version = safe_getattr(entry, 'name')

                with factory.begin(pkgname + ' ' + version) as pkg:
                    # XXX: package naming is inconsistent (either plain name like kdenlive or
                    # domain prefixed like com.abisource.abiword), but it's assumed that
                    # everything up to the last dot may be stripped (#863)
                    pkg.add_name(packages[pkgname].title, NameType.NPACKD_TITLE)
                    pkg.add_name(pkgname, NameType.NPACKD_FULLNAME)
                    pkg.add_name(pkgname.split('.')[-1], NameType.NPACKD_LASTNAME)
                    pkg.set_version(version)

                    pkg.add_downloads((e.text for e in entry.findall('url')))

                    # from previously parsed <license> and <package> entries
                    pkg.add_licenses(licenses[license_] for license_ in packages[pkgname].licenses)
                    pkg.add_categories(_filter_categories(packages[pkgname].categories))
                    pkg.add_homepages(packages[pkgname].urls)

                yield pkg
Example #2
0
    def iter_parse(self, path: str, factory: PackageFactory,
                   transformer: PackageTransformer) -> Iterable[PackageMaker]:
        licenses: Dict[str, str] = {}
        packages: Dict[str, Tuple[str, List[str], List[str], List[str]]] = {}

        for entry in iter_xml_elements_at_level(
                path, 1, ['license', 'package', 'version']):
            if entry.tag == 'license':
                licenses[safe_getattr(entry,
                                      'name')] = safe_findtext(entry, 'title')
            elif entry.tag == 'package':
                packages[safe_getattr(entry, 'name')] = (
                    safe_findtext(entry, 'title'),
                    safe_findalltexts(entry, 'license'),
                    safe_findalltexts(entry, 'category'),
                    safe_findalltexts(entry, 'url'),
                )
            elif entry.tag == 'version':
                pkgname = safe_getattr(entry, 'package')
                version = safe_getattr(entry, 'name')

                with factory.begin(pkgname + ' ' + version) as pkg:
                    # XXX: package naming is inconsistent (either plain name like kdenlive or
                    # domain prefixed like com.abisource.abiword), but it's assumed that
                    # everything up to the last dot may be stripped (#863)
                    pkg.set_name(pkgname)
                    pkg.set_basename(pkgname.split('.')[-1])
                    pkg.set_version(version)

                    pkg.add_downloads((e.text for e in entry.findall('url')))

                    # from previously parsed <license> and <package> entries
                    pkg.set_summary(packages[pkgname][0])
                    pkg.add_licenses(licenses[l] for l in packages[pkgname][1])
                    pkg.add_categories(_filter_categories(
                        packages[pkgname][2]))
                    pkg.add_homepages(_filter_categories(packages[pkgname][3]))

                yield pkg
Example #3
0
    def iter_parse(self, path: str, factory: PackageFactory,
                   transformer: PackageTransformer) -> Iterable[PackageMaker]:
        normalize_version = VersionStripper().strip_right_greedy('+')

        skipped_archs: Dict[str, int] = Counter()

        if self._arch_from_filename:
            factory.log('mitigation for incorrect <arch></arch> enabled',
                        severity=Logger.WARNING)

        for entry in iter_xml_elements_at_level(
                path, 1, ['{http://linux.duke.edu/metadata/common}package']):
            if self._arch_from_filename:
                # XXX: openmandriva 3 hack, to be removed when it EoLs
                location_elt = entry.find(
                    '{http://linux.duke.edu/metadata/common}location')
                if location_elt is None:
                    raise RuntimeError('Cannot find <location> element')
                arch = nevra_parse(safe_getattr(location_elt, 'href'))[4]
            else:
                arch = safe_findtext(
                    entry, '{http://linux.duke.edu/metadata/common}arch')

            is_src = arch == 'src'

            if (is_src and not self._src) or (not is_src and not self._binary):
                skipped_archs[arch] += 1
                continue

            with factory.begin() as pkg:
                name = safe_findtext(
                    entry, '{http://linux.duke.edu/metadata/common}name')
                if '%{' in name:
                    pkg.log('incorrect package name (unexpanded substitution)',
                            severity=Logger.ERROR)
                    continue

                if is_src:
                    pkg.add_name(name, NameType.SRCRPM_NAME)
                else:
                    pkg.add_name(name, NameType.BINRPM_NAME)
                    sourcerpm = safe_findtext(
                        entry, '{http://linux.duke.edu/metadata/common}format/'
                        '{http://linux.duke.edu/metadata/rpm}sourcerpm')
                    pkg.add_name(
                        nevra_parse(sourcerpm)[0], NameType.BINRPM_SRCNAME)

                version_elt = entry.find(
                    '{http://linux.duke.edu/metadata/common}version')
                if version_elt is None:
                    raise RuntimeError('Cannot find <version> element')

                epoch = version_elt.attrib['epoch']
                version = version_elt.attrib['ver']
                release = version_elt.attrib['rel']

                fixed_version = version

                match = re.match('0\\.[0-9]+\\.((?:alpha|beta|rc)[0-9]+)\\.',
                                 release)
                if match:
                    # known pre-release schema: https://fedoraproject.org/wiki/Packaging:Versioning#Prerelease_versions
                    fixed_version += '-' + match.group(1)
                elif release < '1':
                    # unknown pre-release schema: https://fedoraproject.org/wiki/Packaging:Versioning#Some_definitions
                    # most likely a snapshot
                    pkg.set_flags(PackageFlags.IGNORE)

                pkg.set_version(fixed_version, normalize_version)
                pkg.set_rawversion(
                    nevra_construct(None, epoch, version, release))

                pkg.set_summary(
                    entry.findtext(
                        '{http://linux.duke.edu/metadata/common}summary'))
                pkg.add_homepages(
                    entry.findtext(
                        '{http://linux.duke.edu/metadata/common}url'))
                pkg.add_categories(
                    entry.findtext(
                        '{http://linux.duke.edu/metadata/common}format/'
                        '{http://linux.duke.edu/metadata/rpm}group'))
                pkg.add_licenses(
                    entry.findtext(
                        '{http://linux.duke.edu/metadata/common}format/'
                        '{http://linux.duke.edu/metadata/rpm}license'))
                pkg.set_arch(
                    entry.findtext(
                        '{http://linux.duke.edu/metadata/common}arch'))

                packager = entry.findtext(
                    '{http://linux.duke.edu/metadata/common}packager')
                if packager:
                    pkg.add_maintainers(extract_maintainers(packager))

                yield pkg

        for arch, numpackages in sorted(skipped_archs.items()):
            factory.log(
                'skipped {} packages(s) with disallowed architecture {}'.
                format(numpackages, arch))