From f9166541f409cfab4255400d7cde575bb7f734d7 Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Sun, 3 Jul 2022 23:27:49 -0700 Subject: [PATCH] add tweak treeinfo for dnf_utils --- iso/empanadas/empanadas/util/dnf_utils.py | 75 ++++++++++++++++++- iso/empanadas/empanadas/util/iso_utils.py | 88 ----------------------- 2 files changed, 73 insertions(+), 90 deletions(-) diff --git a/iso/empanadas/empanadas/util/dnf_utils.py b/iso/empanadas/empanadas/util/dnf_utils.py index c7e9a79..4332986 100644 --- a/iso/empanadas/empanadas/util/dnf_utils.py +++ b/iso/empanadas/empanadas/util/dnf_utils.py @@ -96,6 +96,7 @@ class RepoSync: self.repo = repo self.extra_files = rlvars['extra_files'] self.gpgkey = gpgkey + self.checksum = rlvars['checksum'] self.compose_id = '{}-{}-{}'.format( config['shortname'], @@ -251,8 +252,9 @@ class RepoSync: if self.refresh_extra_files and not self.fullrun: self.deploy_extra_files(sync_root, global_work_root) - # This does NOT overwrite treeinfo files. This just ensures they exist - # and are configured correctly. + # deploy_treeinfo does NOT overwrite any treeinfo files. However, + # tweak_treeinfo calls out to a method that does. This should not + # cause issues as the method is fairly static in nature. if self.refresh_treeinfo and not self.fullrun: self.deploy_treeinfo(self.repo, sync_root, self.arch) self.tweak_treeinfo(self.repo, sync_root, self.arch) @@ -1214,6 +1216,75 @@ class RepoSync: This modifies treeinfo for the primary repository. If the repository is listed in the iso_map as a non-disc, it will be considered for modification. """ + variants_to_tweak = [] + + arches_to_tree = self.arches + if arch: + arches_to_tree = [arch] + + repos_to_tree = self.repos + if repo and not self.fullrun: + repos_to_tree = [repo] + + for r in repos_to_tree: + entry_name_list = [] + repo_name = r + arch_tree = arches_to_tree.copy() + + if r in self.iso_map['images']: + variants_to_tweak.append(r) + + for v in variants_to_tweak: + for a in arches_to_tree: + image = os.path.join(sync_root, v, a, 'os') + imagemap = self.iso_map['images'][v] + data = { + 'arch': a, + 'variant': v, + 'variant_path': image, + 'checksum': self.checksum, + 'distname': self.distname, + 'fullname': self.fullname, + 'shortname': self.shortname, + 'release': self.fullversion, + 'timestamp': self.timestamp, + } + + try: + Shared.treeinfo_modify_write(data, imagemap) + except Exception as e: + self.log.error( + '[' + Color.BOLD + Color.RED + 'FAIL' + Color.END + '] ' + + 'There was an error writing treeinfo.' + ) + self.log.error(e) + + if self.fullrun: + ksimage = os.path.join(sync_root, v, a, 'kickstart') + ksdata = { + 'arch': a, + 'variant': v, + 'variant_path': image, + 'checksum': self.checksum, + 'distname': self.distname, + 'fullname': self.fullname, + 'shortname': self.shortname, + 'release': self.fullversion, + 'timestamp': self.timestamp, + } + ksdata.clear() + + try: + Shared.treeinfo_modify_write(ksdata, imagemap) + except Exception as e: + self.log.error( + '[' + Color.BOLD + Color.RED + 'FAIL' + Color.END + '] ' + + 'There was an error writing treeinfo.' + ) + self.log.error(e) + + data.clear() + imagemap.clear() def run_compose_closeout(self): """ diff --git a/iso/empanadas/empanadas/util/iso_utils.py b/iso/empanadas/empanadas/util/iso_utils.py index ee682c9..c61e0fe 100644 --- a/iso/empanadas/empanadas/util/iso_utils.py +++ b/iso/empanadas/empanadas/util/iso_utils.py @@ -821,94 +821,6 @@ class IsoBuild: ) self.log.error(e) - #treeinfo = os.path.join(image, '.treeinfo') - #discinfo = os.path.join(image, '.discinfo') - #mediarepo = os.path.join(image, 'media.repo') - #imagemap = self.iso_map['images'][variant] - #primary = imagemap['variant'] - #repos = imagemap['repos'] - #is_disc = False - - #if imagemap['disc']: - # is_disc = True - # discnum = 1 - - # load up productmd - #ti = productmd.treeinfo.TreeInfo() - #ti.load(treeinfo) - - # Set the name - #ti.release.name = self.distname - #ti.release.short = self.shortname - # Set the version (the initial lorax run does this, but we are setting - # it just in case) - #ti.release.version = self.release - # Assign the present images into a var as a copy. For each platform, - # clear out the present dictionary. For each item and path in the - # assigned var, assign it back to the platform dictionary. If the path - # is empty, continue. Do checksums afterwards. - #plats = ti.images.images.copy() - #for platform in ti.images.images: - # ti.images.images[platform] = {} - # for i, p in plats[platform].items(): - # if not p: - # continue - # if 'boot.iso' in i and is_disc: - # continue - # ti.images.images[platform][i] = p - # ti.checksums.add(p, self.checksum, root_dir=image) - - # stage2 checksums - #if ti.stage2.mainimage: - # ti.checksums.add(ti.stage2.mainimage, self.checksum, root_dir=image) - - #if ti.stage2.instimage: - # ti.checksums.add(ti.stage2.instimage, self.checksum, root_dir=image) - - # If we are a disc, set the media section appropriately. - #if is_disc: - # ti.media.discnum = discnum - # ti.media.totaldiscs = discnum - - # Create variants - # Note to self: There's a lot of legacy stuff running around for - # Fedora, ELN, and RHEL in general. This is the general structure, - # apparently. But there could be a chance it'll change. We may need to - # put in a configuration to deal with it at some point. - #ti.variants.variants.clear() - #for y in repos: - # if y in ti.variants.variants.keys(): - # vari = ti.variants.variants[y] - # else: - # vari = productmd.treeinfo.Variant(ti) - - # vari.id = y - # vari.uid = y - # vari.name = y - # vari.type = "variant" - # if is_disc: - # vari.paths.repository = y - # vari.paths.packages = y + "/Packages" - # else: - # if y == primary: - # vari.paths.repository = "." - # vari.paths.packages = "Packages" - # else: - # vari.paths.repository = "../../../" + y + "/" + arch + "/os" - # vari.paths.packages = "../../../" + y + "/" + arch + "/os/Packages" - - # if y not in ti.variants.variants.keys(): - # ti.variants.add(vari) - - # del vari - - # Set default variant - #ti.dump(treeinfo, main_variant=primary) - # Set discinfo - #Shared.discinfo_write(self.timestamp, self.fullname, arch, discinfo) - # Set media.repo - #Shared.media_repo_write(self.timestamp, self.fullname, mediarepo) - # Next set of functions are loosely borrowed (in concept) from pungi. Some # stuff may be combined/mixed together, other things may be simplified or # reduced in nature.