From 23ced26588a398a120c12daaeb6c8b5221060520 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Thu, 31 May 2018 17:00:38 -0400 Subject: [PATCH] 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 --- pungi.spec | 1 + pungi/phases/createrepo.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pungi.spec b/pungi.spec index e0779e6f..0dcccfbb 100644 --- a/pungi.spec +++ b/pungi.spec @@ -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 diff --git a/pungi/phases/createrepo.py b/pungi/phases/createrepo.py index 61821d92..e3c9c830 100644 --- a/pungi/phases/createrepo.py +++ b/pungi/phases/createrepo.py @@ -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))