From 620263c34b0685d49822141daa6ed48d3b8ed6e0 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Oct 18 2019 13:44:45 +0000 Subject: combine common code --- diff --git a/module_build_service/builder/KojiContentGenerator.py b/module_build_service/builder/KojiContentGenerator.py index c90f5fa..fa7e689 100644 --- a/module_build_service/builder/KojiContentGenerator.py +++ b/module_build_service/builder/KojiContentGenerator.py @@ -268,11 +268,6 @@ class KojiContentGenerator(object): ret = self.module.nvr if self.devel: ret["name"] += "-devel" - mmd = self.module.mmd() - mmd = mmd.copy(mmd.get_module_name() + "-devel") - modulemd_str = mmd_to_str(mmd) - else: - modulemd_str = self.module.modulemd ret[u"source"] = self.module.scmurl ret[u"start_time"] = calendar.timegm(self.module.time_submitted.utctimetuple()) ret[u"end_time"] = calendar.timegm(self.module.time_completed.utctimetuple()) @@ -281,7 +276,7 @@ class KojiContentGenerator(object): u"module": { u"module_build_service_id": self.module.id, u"content_koji_tag": self.module.koji_tag, - u"modulemd_str": modulemd_str, + u"modulemd_str": self._get_fixed_mmd(), u"name": ret["name"], u"stream": self.module.stream, u"version": self.module.version, @@ -332,6 +327,16 @@ class KojiContentGenerator(object): u"type": u"rpm", } + def _get_fixed_mmd(self): + if self.devel: + mmd = self.module.mmd() + mmd = mmd.copy(mmd.get_module_name() + "-devel") + ret = mmd_to_str(mmd) + else: + ret = self.mmd + + return ret + def _get_arch_mmd_output(self, output_path, arch): """ Returns the CG "output" dict for architecture specific modulemd file. @@ -757,14 +762,8 @@ class KojiContentGenerator(object): prepdir = tempfile.mkdtemp(prefix="koji-cg-import") mmd_path = os.path.join(prepdir, "modulemd.txt") log.info("Writing generic modulemd.yaml to %r" % mmd_path) - if self.devel: - mmd = self.module.mmd() - mmd = mmd.copy(mmd.get_module_name() + "-devel") - contents = mmd_to_str(mmd) - else: - contents = self.mmd with open(mmd_path, "w", encoding="utf-8") as mmd_f: - mmd_f.write(contents) + mmd_f.write(self._get_fixed_mmd()) mmd_path = os.path.join(prepdir, "modulemd.src.txt") self._download_source_modulemd(self.module.mmd(), mmd_path)