Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[tesh] try to port to windows
[simgrid.git] / tools / platf_route_rulebased2full.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # Copyright (c) 2013-2014. The SimGrid Team.
5 # All rights reserved.
6
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the license (GNU LGPL) which comes with this package.
9
10 import sys, re
11 from lxml import etree
12
13 xml = etree.parse(sys.argv[1])
14 for e in xml.xpath('//*[@routing="RuleBased"]'):
15   e.attrib['routing'] = "Full"
16   ids = e.xpath('./*[@id]/@id')
17   done = set()  
18   for asr in e.xpath("./ASroute"):
19     src_ids = {}
20     dst_ids = {}
21     for id in ids:
22       src_s = re.search(r"%s"%asr.attrib['src'], id)
23       dst_s = re.search(r"%s"%asr.attrib['dst'], id)
24       if src_s  :
25         src_ids[id] = src_s
26       if dst_s:
27         dst_ids[id] = dst_s
28     for sid, smat in src_ids.items():
29       for did, dmat in dst_ids.items():
30         todo = tuple(sorted((smat.group(1), dmat.group(1))))
31         if todo not in done or asr.attrib.get("symmetrical")=="NO":
32           done.add(todo)
33           dasr = etree.tounicode(asr)
34           dasr = dasr.replace("$1src", smat.group(1))
35           dasr = dasr.replace("$1dst", dmat.group(1))
36           dasr = etree.fromstring(dasr)
37           dasr.tag = "__ASroute__"
38           dasr.attrib['src'] = sid
39           dasr.attrib['dst'] = did
40           asr.addnext(dasr)
41     asr.getparent().remove(asr)
42
43 print etree.tounicode(xml).replace("__ASroute__", "ASroute")
44