Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change parameters order for msg_file_read, msg_file_write and in all their internal...
[simgrid.git] / tools / platf_route_rulebased2full.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import sys, re
5 from lxml import etree
6
7 xml = etree.parse(sys.argv[1])
8 for e in xml.xpath('//*[@routing="RuleBased"]'):
9   e.attrib['routing'] = "Full"
10   ids = e.xpath('./*[@id]/@id')
11   done = set()  
12   for asr in e.xpath("./ASroute"):
13     src_ids = {}
14     dst_ids = {}
15     for id in ids:
16       src_s = re.search(r"%s"%asr.attrib['src'], id)
17       dst_s = re.search(r"%s"%asr.attrib['dst'], id)
18       if src_s  :
19         src_ids[id] = src_s
20       if dst_s:
21         dst_ids[id] = dst_s
22     for sid, smat in src_ids.items():
23       for did, dmat in dst_ids.items():
24         todo = tuple(sorted((smat.group(1), dmat.group(1))))
25         if todo not in done or asr.attrib.get("symmetrical")=="NO":
26           done.add(todo)
27           dasr = etree.tounicode(asr)
28           dasr = dasr.replace("$1src", smat.group(1))
29           dasr = dasr.replace("$1dst", dmat.group(1))
30           dasr = etree.fromstring(dasr)
31           dasr.tag = "__ASroute__"
32           dasr.attrib['src'] = sid
33           dasr.attrib['dst'] = did
34           asr.addnext(dasr)
35     asr.getparent().remove(asr)
36
37 print etree.tounicode(xml).replace("__ASroute__", "ASroute")
38