From b5d5e8da4a87e2d44f8978fa01669fe67cc36a45 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 9 Aug 2018 17:00:15 -0400 Subject: [PATCH] pungi/ostree: Convert rpm-ostree YAML to JSON We'd like to use YAML for future rpm-ostree work; among other things it supports comments. See https://pagure.io/fedora-atomic/pull-request/125 and the original https://github.com/projectatomic/rpm-ostree/pull/1377 Signed-off-by: Colin Walters --- pungi/ostree/tree.py | 2 +- pungi/ostree/utils.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pungi/ostree/tree.py b/pungi/ostree/tree.py index e30d3178..d430a467 100644 --- a/pungi/ostree/tree.py +++ b/pungi/ostree/tree.py @@ -101,7 +101,7 @@ class Tree(OSTree): # override ref value in treefile update_dict['ref'] = self.ostree_ref - tweak_treeconf(self.treefile, source_repos=repos, keep_original_sources=keep_original_sources, update_dict=update_dict) + self.treefile = tweak_treeconf(self.treefile, source_repos=repos, keep_original_sources=keep_original_sources, update_dict=update_dict) self.commitid_file = make_log_file(self.logdir, 'commitid') diff --git a/pungi/ostree/utils.py b/pungi/ostree/utils.py index 25cb42fb..39d3a379 100644 --- a/pungi/ostree/utils.py +++ b/pungi/ostree/utils.py @@ -14,6 +14,7 @@ # along with this program; if not, see . +import yaml import json import logging import os @@ -72,13 +73,20 @@ def tweak_treeconf(treeconf, source_repos=None, keep_original_sources=False, upd Additionally, other values can be passed to method by 'update_dict' parameter to update treefile content. """ - treeconf_dir = os.path.dirname(treeconf) - with open(treeconf, 'r') as f: - treeconf_content = json.load(f) # backup the old tree config os.rename(treeconf, '{0}.bak'.format(treeconf)) + treeconf_dir = os.path.dirname(treeconf) + with open(treeconf, 'r') as f: + # rpm-ostree now supports YAML: https://github.com/projectatomic/rpm-ostree/pull/1377 + # but we'll end up converting it to JSON. + if treeconf.endswith('.yaml'): + treeconf_content = yaml.load(f) + treeconf = treeconf.replace('.yaml', '.json') + else: + treeconf_content = json.load(f) + repos = [] if source_repos: # Sort to ensure reliable ordering @@ -114,3 +122,4 @@ def tweak_treeconf(treeconf, source_repos=None, keep_original_sources=False, upd # update tree config to add new repos with open(treeconf, 'w') as f: json.dump(treeconf_content, f, indent=4) + return treeconf