Add content_licenses to module metadata
During the createrepo phase for Modular variants, this will now interrogate the repodata from the "work" repositories for the set of licenses in use by each of the RPMs in a module and add those to the metadata to be written out into the final repodata location. Merges: https://pagure.io/pungi/pull-request/968 Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
This commit is contained in:
parent
8b9508b027
commit
23ced26588
@ -31,6 +31,7 @@ Requires: python-productmd >= 1.11
|
||||
Requires: python-kickstart
|
||||
Requires: libselinux-python
|
||||
Requires: createrepo_c
|
||||
Requires: python3-createrepo_c
|
||||
Requires: python-lxml
|
||||
Requires: koji >= 1.10.1-13
|
||||
Requires: jigdo
|
||||
|
@ -40,6 +40,8 @@ from pungi.arch import tree_arch_to_yum_arch
|
||||
import productmd.rpms
|
||||
import productmd.modules
|
||||
|
||||
import createrepo_c as cr
|
||||
|
||||
|
||||
createrepo_lock = threading.Lock()
|
||||
createrepo_dirs = set()
|
||||
@ -82,6 +84,21 @@ class CreaterepoPhase(PhaseBase):
|
||||
self.modules_metadata.write_modules_metadata()
|
||||
|
||||
|
||||
def get_licenses_from_repo(repo_path):
|
||||
result = {}
|
||||
md = cr.Metadata()
|
||||
md.locate_and_load_xml(repo_path)
|
||||
for key in md.keys():
|
||||
pkg = md.get(key)
|
||||
nevra = "%s-%s:%s-%s.%s" % (pkg.name,
|
||||
pkg.epoch if pkg.epoch else "0",
|
||||
pkg.version,
|
||||
pkg.release,
|
||||
pkg.arch)
|
||||
result[nevra] = pkg.rpm_license
|
||||
return result
|
||||
|
||||
|
||||
def create_variant_repo(compose, arch, variant, pkg_type, modules_metadata=None):
|
||||
types = {
|
||||
'rpm': ('binary',
|
||||
@ -193,6 +210,12 @@ def create_variant_repo(compose, arch, variant, pkg_type, modules_metadata=None)
|
||||
if arch in variant.arch_mmds and Modulemd is not None:
|
||||
modules = []
|
||||
metadata = []
|
||||
|
||||
# Interrogate the RPM repodata and add all licenses for these RPMs to the
|
||||
# module metadata
|
||||
license_data = get_licenses_from_repo(
|
||||
compose.paths.work.arch_repo(arch))
|
||||
|
||||
for module_id, mmd in variant.arch_mmds[arch].items():
|
||||
# Create copy of architecture specific mmd to filter out packages
|
||||
# which are not part of this particular repo.
|
||||
@ -206,11 +229,17 @@ def create_variant_repo(compose, arch, variant, pkg_type, modules_metadata=None)
|
||||
|
||||
module_rpms = set()
|
||||
repo_artifacts = Modulemd.SimpleSet()
|
||||
rpm_licenses = Modulemd.SimpleSet()
|
||||
for rpm_nevra in rpm_nevras:
|
||||
if artifacts.contains(rpm_nevra):
|
||||
repo_artifacts.add(rpm_nevra)
|
||||
module_rpms.add(rpm_nevra)
|
||||
# Not all RPMs have license data (*-debuginfo does not),
|
||||
# so add any that do and don't worry about the remainder.
|
||||
if rpm_nevra in license_data:
|
||||
rpm_licenses.add(license_data[rpm_nevra])
|
||||
repo_mmd.set_rpm_artifacts(repo_artifacts)
|
||||
repo_mmd.set_content_licenses(rpm_licenses)
|
||||
if module_rpms: # do not create metadata if there is empty rpm list
|
||||
if modules_metadata: # some unittests call this method without parameter modules_metadata and its default is None
|
||||
metadata.append((module_id, module_rpms))
|
||||
|
Loading…
Reference in New Issue
Block a user