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 <walters@verbum.org>
This commit is contained in:
Colin Walters 2018-08-09 17:00:15 -04:00 committed by Lubomír Sedlář
parent 2fa1f09827
commit b5d5e8da4a
2 changed files with 13 additions and 4 deletions

View File

@ -101,7 +101,7 @@ class Tree(OSTree):
# override ref value in treefile # override ref value in treefile
update_dict['ref'] = self.ostree_ref 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') self.commitid_file = make_log_file(self.logdir, 'commitid')

View File

@ -14,6 +14,7 @@
# along with this program; if not, see <https://gnu.org/licenses/>. # along with this program; if not, see <https://gnu.org/licenses/>.
import yaml
import json import json
import logging import logging
import os 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 Additionally, other values can be passed to method by 'update_dict' parameter to
update treefile content. 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 # backup the old tree config
os.rename(treeconf, '{0}.bak'.format(treeconf)) 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 = [] repos = []
if source_repos: if source_repos:
# Sort to ensure reliable ordering # 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 # update tree config to add new repos
with open(treeconf, 'w') as f: with open(treeconf, 'w') as f:
json.dump(treeconf_content, f, indent=4) json.dump(treeconf_content, f, indent=4)
return treeconf