diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2018-02-14 09:00:10 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-14 09:00:10 -0800 |
commit | 75290a8e32d1658933b59957f8406e2379710ec2 (patch) | |
tree | 5895954b968f049cebeb4ec7784146a9aac14e7c /roles/lib_openshift/library/oc_image.py | |
parent | 07614f8b8d4cd59941d168c4f14ebed49ec8371e (diff) | |
parent | 42fd5866e3eeb878f7d890005bf69365fade5482 (diff) | |
download | openshift-75290a8e32d1658933b59957f8406e2379710ec2.tar.gz openshift-75290a8e32d1658933b59957f8406e2379710ec2.tar.bz2 openshift-75290a8e32d1658933b59957f8406e2379710ec2.tar.xz openshift-75290a8e32d1658933b59957f8406e2379710ec2.zip |
Merge pull request #7140 from kwoodson/yedit_json_files
Automatic merge from submit-queue.
Adding ability to yedit json files.
Adding feature of modifying json to yedit.
Generated files makes this appear large. There are approximately 8 real lines of change.
Diffstat (limited to 'roles/lib_openshift/library/oc_image.py')
-rw-r--r-- | roles/lib_openshift/library/oc_image.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/roles/lib_openshift/library/oc_image.py b/roles/lib_openshift/library/oc_image.py index e71e2eb5c..b479857ad 100644 --- a/roles/lib_openshift/library/oc_image.py +++ b/roles/lib_openshift/library/oc_image.py @@ -335,10 +335,16 @@ class Yedit(object): # pragma: no cover pass # Try to use RoundTripDumper if supported. - try: - Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) - except AttributeError: - Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + if self.content_type == 'yaml': + try: + Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper)) + except AttributeError: + Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False)) + elif self.content_type == 'json': + Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True)) + else: + raise YeditException('Unsupported content_type: {}.'.format(self.content_type) + + 'Please specify a content_type of yaml or json.') return (True, self.yaml_dict) @@ -386,7 +392,7 @@ class Yedit(object): # pragma: no cover # Try to use RoundTripLoader if supported. try: - self.yaml_dict = yaml.safe_load(contents, yaml.RoundTripLoader) + self.yaml_dict = yaml.load(contents, yaml.RoundTripLoader) except AttributeError: self.yaml_dict = yaml.safe_load(contents) @@ -631,7 +637,12 @@ class Yedit(object): # pragma: no cover curr_value = invalue if val_type == 'yaml': - curr_value = yaml.load(invalue) + try: + # AUDIT:maybe-no-member makes sense due to different yaml libraries + # pylint: disable=maybe-no-member + curr_value = yaml.safe_load(invalue, Loader=yaml.RoundTripLoader) + except AttributeError: + curr_value = yaml.safe_load(invalue) elif val_type == 'json': curr_value = json.loads(invalue) @@ -700,6 +711,7 @@ class Yedit(object): # pragma: no cover '''perform the idempotent crud operations''' yamlfile = Yedit(filename=params['src'], backup=params['backup'], + content_type=params['content_type'], separator=params['separator']) state = params['state'] |