here i have added a code to generate xml_tags, This is what my output is :
md5 value = "sdfhsdkjgfjw35378563"
repOperation value = "push"
size value = "toolarge"
images value = "/home/rakesh/from_t_jack/imag1.ipds"
status value = "completed"
replication value = "mode"
sdlist value = "f:"
I have used dictionary. I am unable to get correct sort
of my dictionary. I want the dictionary to be sorted and printed as the order i declared.
one other problem is , if the output is observed in 6th line, the output is kinda reversed , i was expecting :mode value = "replication"
. but the output is reversed.i do not know why it is behaving in this manner. I was wondering how to fix these 2 issues . Here is my Code.
def generate_tag(name,val):
full_tag = ''+name+' value = "'+val+'"'
return full_tag
def auto_xml(sdList,repOperation,images,status,md5):
tags = {'repOperationTag' :{'repOperation_tag_name':'repOperation' ,
'repOperation_val' : repOperation },
'modeTag' :{'mode_tag_name':'mode' ,
'mode_val' : 'replication' },
'imagesTag' :{'images_tag_name': 'images',
'images_val' : images },
'statusTag' :{'status_tag_name':'status' ,
'status_val' : status},
'sizeTag' :{'size_tag_name':'size' ,
'size_val' : 'toolarge'},
'md5Tag' :{'md5_tag_name' : 'md5' ,
'md5_val' : md5} ,
'sdListTag' :{'sdList_tag_name': 'sdlist' ,
'sdList_val' : sdList} }
count = 0
tag_len = len(tags)
while count < tag_len :
inner = tags[tags.keys()[count]]
tag_name = inner[inner.keys()[0]]
tag_val = inner[inner.keys()[1]]
full_tag = generate_tag(tag_name,tag_val)
print full_tag
count = count + 1
def myordered_dict():
from collections import OrderedDict
tags = {'A_repOperationTag' :{'tag_name':'repOperation' ,
'tag_val' : repOperation },
'B_modeTag' :{'tag_name':'mode' ,
'tag_val' : 'replication' },
'C_imagesTag' :{'tag_name': 'images',
'tag_val' : images },
'D_statusTag' :{'tag_name':'status' ,
'tag_val' : status},
'E_sizeTag' :{'tag_name':'size' ,
'tag_val' : 'toolarge'},
'F_md5Tag' :{'tag_name' : 'md5' ,
'tag_val' : md5} ,
'G_sdListTag' :{'tag_name': 'sdlist' ,
'tag_val' : sdList},
'H_machinename' :{'tag_name': 'hostname' ,
'tag_val' : 'xp_vm'} }
tags = OrderedDict(sorted(tags.items(), key=lambda t: t[0]))