yaml_file1.yaml
container:
name: NAME1
number: 222
type:
compression:lz
function: boot_a
type_revno:REV123
type_prodno: REV345
fw:
prodno:ABC123
revno:ABC345
prodno:DEF123
revno:DEF345
url:"file:///path1"
slot : 1
compression:zip
function: boot_b
type_revno:REV111
type_prodno: REV222
fw:
prodno:XYZ111
revno:XYZ222
prodno: UVW111
revno:UVW222
url: "file:///path2"
slot : 2
compression:lz
function: appl_a
type_revno:REV333
type_prodno: REV444
fw:
prodno:XYZ333
revno:XYZ444
prodno: UVW333
revno:UVW444
url: "file:///path3"
slot : 3
compression:zip
function: appl_b
type_revno:REV333
type_prodno: REV444
type_revno:REV333
type_prodno: REV444
fw:
prodno:XYZ333
revno:XYZ444
prodno: UVW333
revno:UVW444
url: "file:///path4"
slot : 4
*********************************
yaml_file2.yaml
container:
name: NAME1
number: 222
timestamp: 1634495717
type:
compression:lz
function: boot_a
type_revno:REV123
type_prodno: REV345
fw:
prodno:ABC123
revno:ABC345
prodno:DEF123
revno:DEF345
offset: 0
md5sum : (some md5sum value)
size: 3000
slot : 1
compression:zip
function:boot_b
type_revno:REV111
type_prodno: REV222
fw:
prodno:XYZ111
revno:XYZ222
prodno: UVW111
revno:UVW222
offset : 1
md5sum : (some md5sum value)
size: 2000
slot : 2
compression:lz
function: appl_a
type_revno:REV111
type_prodno: REV222
fw:
prodno:XYZ111
revno:XYZ222
prodno: UVW111
revno:UVW222
offset: 2
md5sum : (some md5sum value)
size : 1000
slot : 3
compression:zip
function: appl_b
type_revno:REV333
type_prodno: REV444
type_revno:REV333
type_prodno: REV444
fw:
prodno:XYZ333
revno:XYZ444
prodno: UVW333
revno:UVW444
offset: 3
md5sum : (some md5sum value)
slot : 4
As we can see, yaml_file2.yaml has url parameter missing for all the instances of 'type'. I want to pick up 'url' parameter and its value from yaml_file1.yaml and put it for corresponding instances of 'type' in yaml_file2.yaml. We can differentiate the 'type' from one another using 'function' names for mapping.
Can we do this in python using dictionary methods?
I am an amateur and still learning. So far I have only understood about accessing non-nested dictionary.
If I try to access urls like this:
with open('yaml_file1.yaml','r') as ingen:
datagen = yaml.full_load(ingen)
for k, v in datagen["type"].items():
print (datagen["type"][k]["url"])
I get
Traceback (most recent call last):
File "compareyaml.py", line 43, in <module>
for k, v in datagen["type"].items():
AttributeError: 'list' object has no attribute 'items'
Can someone please help?