Parse YAML with as YAML1.1 standard

Ruamel.yaml is YAML1.2 compatible by default. The YAML1.2 does not
support octals starts with 0 (the octals are required to start with
0o). For example, the octal number 0755 with be transferred into 755.
This commit set the ruamel.yaml load the filed as version 1.1. After
this commit, the octal number will be transferred to decimal. For
example, the octal 0755 will be re-write to 493. And it will be
load/dump correctly in the following steps.

Closes-Bug: 1896530
Change-Id: If8be9d8d4b22ccce99307b5388313ba85a71be74
Signed-off-by: Yuxing Jiang <yuxing.jiang@windriver.com>
This commit is contained in:
Yuxing Jiang 2020-10-26 10:27:06 -04:00
parent 5df0f70f5b
commit 0636bbc87e
2 changed files with 5 additions and 2 deletions

View File

@ -315,7 +315,7 @@ def merge_yaml(yaml_merged, yaml_new):
yaml_out = collections.OrderedDict() yaml_out = collections.OrderedDict()
for yaml_file in yaml_files: for yaml_file in yaml_files:
print 'Merging yaml from file: %s' % yaml_file print 'Merging yaml from file: %s' % yaml_file
for document in yaml.load_all(open(yaml_file), Loader=yaml.RoundTripLoader, preserve_quotes=True): for document in yaml.load_all(open(yaml_file), Loader=yaml.RoundTripLoader, preserve_quotes=True, version=(1, 1)):
document_name = (document['schema'], document['metadata']['schema'], document['metadata']['name']) document_name = (document['schema'], document['metadata']['schema'], document['metadata']['name'])
if document_name in yaml_out: if document_name in yaml_out:
merge_yaml(yaml_out[document_name], document) merge_yaml(yaml_out[document_name], document)

View File

@ -160,7 +160,10 @@ def main(argv):
# Load chart into dictionary(s) and then modify any image locations/tags if required # Load chart into dictionary(s) and then modify any image locations/tags if required
for document in yaml.load_all( for document in yaml.load_all(
open(yaml_file), Loader=yaml.RoundTripLoader, preserve_quotes=True): open(yaml_file),
Loader=yaml.RoundTripLoader,
preserve_quotes=True,
version=(1, 1)):
document_name = (document['schema'], document_name = (document['schema'],
document['metadata']['schema'], document['metadata']['schema'],
document['metadata']['name']) document['metadata']['name'])