def extract_save_yang(dirname,capa):
modre = re.compile("module=([^&\?]+)").search(capa)
if modre:
global count_yangs, count_yangs_written
count_yangs += 1
modname = modre.groups()[0]
c.send_msg(get_schema_msg(modname))
reply = c.recv_msg()
d = xml.dom.minidom.parseString(reply)
if d is not None:
d = d.firstChild
if d is not None:
d = d.firstChild
strip(d)
if (d.namespaceURI == nc_ns and
d.localName == 'rpc-error'):
print "Could not get schema for %s.yang"%modname
return
## Can't find some good way to extract actual YANG module
## from minidom, so here goes:
yangre = re.compile(".*(module +[a-zA-Z0-9_-]+ *{.+}).*</data>.*",
re.MULTILINE|re.DOTALL).search(reply)
if yangre:
yangtext = yangre.groups()[0]
yangtext = yangtext.replace("<","<").\
replace(">",">").\
replace("&","&").\
replace(""","\'")
filename = "%s/%s.yang"%(dirname,modname)
try:
f = open(filename,"w")
print>>f,yangtext
f.close()
print "Wrote schema into %s"%filename
count_yangs_written += 1
except:
print "Could not write schema into %s"%filename
else:
print "Could not parse schema for %s.yang"%modname
评论列表
文章目录