def modify_repo(repo_path, modules):
    tmp = tempfile.mkdtemp()
    path = os.path.join(tmp, "modules.yaml")
    for module in modules:
        Modulemd.dump(modules, path)
    subprocess.check_call(["modifyrepo_c", "--mdtype=modules", path,
                           os.path.join(repo_path, "repodata")])
    os.unlink(path)
    os.rmdir(tmp)
def modify_repo(repo_path, modules):
    tmp = tempfile.mkdtemp()
    path = os.path.join(tmp, "modules.yaml")
    for module in modules:
        Modulemd.dump(modules, path)
    subprocess.check_call([
        "modifyrepo_c", "--mdtype=modules", path,
        os.path.join(repo_path, "repodata")
    ])
    os.unlink(path)
    os.rmdir(tmp)
Пример #3
0
    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
Пример #4
0
def generate_metadata(ctx):
    """
    Generate modulemd-translations YAML.

    :return: 0 on successful creation of modulemd-translation,
    nonzero on failure.
    """

    zanata_rest_url = "%s/rest" % ctx.parent.obj['zanata_url']

    translations = mmdzanata.get_modulemd_translations(
        zanata_rest_url, ctx.parent.obj['zanata_project'],
        ctx.parent.obj['branch'],
        ctx.parent.obj['zanata_translation_document'], ctx.parent.obj['debug'])

    translation_file = "%s-%s.yaml" % (
        ctx.parent.obj['zanata_translation_document'],
        ctx.parent.obj['branch'])

    Modulemd.dump(sorted(translations), translation_file)

    print("Wrote modulemd-translations YAML to %s" % translation_file)
            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]["rpms"])
            profile.set_rpms(profile_rpms)
            mmd.add_profile(profile)

        if name == "httpd":
            dependencies = Modulemd.Dependencies()
            if stream == "2.4":
                dependencies.add_requires_single("base-runtime", "f26")
            elif stream == "2.2":
                dependencies.add_requires("base-runtime", [])
            mmd.add_dependencies(dependencies)

        # iterate through all deps and create context hash in a repeatable manner
        context_hash = hashlib.sha256()
        for dependencies in mmd.peek_dependencies():
            for dep_name, dep_streams in dependencies.peek_requires().items():
                if dep_streams:
                    for dep_stream in dep_streams.get():
                        context_hash.update("%s:%s" % (dep_name, dep_stream))
                else:
                    context_hash.update(dep_name)
        mmd.set_context(context_hash.hexdigest()[:8])

        Modulemd.dump([mmd], os.path.join(module_dir, "%s.%s.yaml" % (module_id, arch)))
Пример #6
0
            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"])
            profile.set_rpms(profile_rpms)
            mmd.add_profile(profile)

        Modulemd.dump([mmd],
                      os.path.join(module_dir,
                                   "%s.%s.yaml" % (module_id, arch)))