def _create_mmd(name, stream, version, rpms=None, profiles=None): rpms = rpms or [] profiles = profiles or {} # profile_name: {pkg_format: [pkg_names]} mmd = Modulemd.Module() mmd.set_mdversion(int(1)) mmd.set_name(str(name)) mmd.set_stream(str(stream)) mmd.set_version(int(version)) sset = Modulemd.SimpleSet() sset.add("LGPLv2") mmd.set_module_licenses(sset) mmd.set_summary(str("Fake module")) mmd.set_description(mmd.peek_summary()) artifacts = Modulemd.SimpleSet() for rpm in rpms: artifacts.add(rpm[:-4]) mmd.set_rpm_artifacts(artifacts) for profile_name in profiles: profile = Modulemd.Profile() profile.set_name(profile_name) profile_rpms = Modulemd.SimpleSet() profile_rpms.set(profiles[profile_name].get("rpms", [])) profile.set_rpms(profile_rpms) mmd.add_profile(profile) return mmd
def handle_build_module(self): result = ActionResult.SUCCESS try: data = json.loads(self.data["data"]) ownername = data["ownername"] projectname = data["projectname"] chroots = data["chroots"] modulemd_data = base64.b64decode(data["modulemd_b64"]).decode("utf-8") project_path = os.path.join(self.opts.destdir, ownername, projectname) self.log.info(modulemd_data) for chroot in chroots: arch = get_chroot_arch(chroot) mmd = Modulemd.ModuleStream() mmd.import_from_string(modulemd_data) mmd.set_arch(arch) artifacts = Modulemd.SimpleSet() srcdir = os.path.join(project_path, chroot) module_tag = "{}+{}-{}-{}".format(chroot, mmd.get_name(), (mmd.get_stream() or ''), (str(mmd.get_version()) or '1')) module_relpath = os.path.join(module_tag, "latest", arch) destdir = os.path.join(project_path, "modules", module_relpath) if os.path.exists(destdir): self.log.warning("Module %s already exists. Omitting.", destdir) else: # We want to copy just the particular module builds # into the module destdir, not the whole chroot os.makedirs(destdir) prefixes = ["{:08d}-".format(x) for x in data["builds"]] dirs = [d for d in os.listdir(srcdir) if d.startswith(tuple(prefixes))] for folder in dirs: shutil.copytree(os.path.join(srcdir, folder), os.path.join(destdir, folder)) self.log.info("Copy directory: %s as %s", os.path.join(srcdir, folder), os.path.join(destdir, folder)) for f in os.listdir(os.path.join(destdir, folder)): if not f.endswith(".rpm") or f.endswith(".src.rpm"): continue artifact = format_filename(zero_epoch=True, *splitFilename(f)) artifacts.add(artifact) mmd.set_rpm_artifacts(artifacts) self.log.info("Module artifacts: %s", mmd.get_rpm_artifacts()) Modulemd.dump([mmd], os.path.join(destdir, "modules.yaml")) if not call_copr_repo(destdir): result = ActionResult.FAILURE except Exception: self.log.exception("handle_build_module failed") result = ActionResult.FAILURE return result
def test_issue24(self): # Verify that we can handle boolean variant types name = stream = context = "x" version = 10 mmd = Modulemd.Module() mmd.set_mdversion(2) mmd.set_name(name) mmd.set_stream(stream) mmd.set_version(int(version)) mmd.set_context(context) mmd.set_summary("foo") mmd.set_description("foo") licenses = Modulemd.SimpleSet() licenses.add("GPL") mmd.set_module_licenses(licenses) d = {"x": GLib.Variant('b', True)} mmd.set_xmd(d) mmd.dumps()
def _create_mmd(name, stream, version, rpms=None, profiles=None): rpms = rpms or [] profiles = profiles or {} # profile_name: {pkg_format: [pkg_names]} mmd = Modulemd.Module() mmd.set_name(str(name)) mmd.set_stream(str(stream)) mmd.set_version(int(version)) licenses = Modulemd.SimpleSet() licenses.add("LGPLv2") mmd.set_module_licenses(licenses) mmd.set_summary(str("Fake module")) mmd.set_description(mmd.get_summary()) for rpm in rpms: mmd.get_rpm_components.add(rpm.rsplit("-", 2)[0], "") mmd.get_rpm_artifacts.add(rpm[:-4]) for profile_name in profiles: profile = Modulemd.Profile() for rpm in profiles[profile_name].get("rpms", []): profile.add_rpm(rpm) profile.set_name(profile_name) mmd.add_profile(profile) return mmd
rpms = sorted(set(rpms) | set(noarch_rpms)) # HACK: force epoch to make test data compatible with libmodulemd >= 1.4.0 rpms_with_epoch = [] for i in rpms: n, v, ra = i.rsplit("-", 2) nevra = "%s-0:%s-%s" % (n, v, ra) rpms_with_epoch.append(nevra) rpms = rpms_with_epoch mmd = Modulemd.Module() mmd.set_mdversion(int(1)) mmd.set_name(name) mmd.set_stream(stream) mmd.set_version(int(version)) sset = Modulemd.SimpleSet() sset.add("LGPLv2") mmd.set_module_licenses(sset) mmd.set_summary("Fake module") mmd.set_description(mmd.peek_summary()) artifacts = Modulemd.SimpleSet() for rpm in rpms: artifacts.add(rpm[:-4]) mmd.set_rpm_artifacts(artifacts) for profile_name in profiles: profile = Modulemd.Profile() profile.set_name(profile_name) profile.set_description("Description for profile %s." % profile_name) profile_rpms = Modulemd.SimpleSet() profile_rpms.set(profiles[profile_name]["rpms"])
def add_filter(self, packages): mmd_set = Modulemd.SimpleSet() for package in packages: mmd_set.add(str(package)) self.mmd.set_rpm_filter(mmd_set)
def __init__(self, name="", stream="", version=0, summary="", config=None): self.config = config licenses = Modulemd.SimpleSet() licenses.add("unknown") self.mmd = Modulemd.ModuleStream(mdversion=1, name=name, stream=stream, version=version, summary=summary, description="", content_licenses=licenses, module_licenses=licenses)