#1019 pungi/ostree: Convert rpm-ostree YAML to JSON
Merged 5 years ago by lsedlar. Opened 5 years ago by walters.
walters/pungi rpmostree-yaml  into  master

file modified
+1 -1
@@ -101,7 +101,7 @@ 

                  # 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')

  

file modified
+12 -3
@@ -14,6 +14,7 @@ 

  # along with this program; if not, see <https://gnu.org/licenses/>.

  

  

+ import yaml

  import json

  import logging

  import os
@@ -72,13 +73,20 @@ 

      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 @@ 

      # update tree config to add new repos

      with open(treeconf, 'w') as f:

          json.dump(treeconf_content, f, indent=4)

+     return treeconf

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

Note: not tested, I don't have a pungi devel environment at the moment

I fixed the failing unit test in #1020 and I'll try to get this tested with actual data.

I'm having trouble running a whole compose with ostree in stage infra, but I can get this piece working. In case Pungi is not doing anything with the treefile, it will be passed to rpm-ostree directly. If it is tweaked, a separate JSON file is written that contains the original content plus any changes. I wouldn't expect the config repo to contain (and use at the same time) both x.yaml and x.json,

I wouldn't expect the config repo to contain (and use at the same time) both x.yaml and x.json,

Yeah I wouldn't expect the repo to contain both yaml and json files.

Commit b85cd7f fixes this pull-request

Pull-Request has been merged by lsedlar

5 years ago

Thanks a lot! Can someone please tell me when this is deployed?