Changeset 5c3d542
- Timestamp:
- Dec 1, 2010 5:07:50 PM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master
- Children:
- d894c21
- Parents:
- 1f356d3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd_image.py
r1f356d3 r5c3d542 39 39 self.add_option("--file", dest="file", 40 40 help="experiment description file") 41 self.add_option("--group", dest="group", default=None,41 self.add_option("--group", dest="group", action="append", default=[], 42 42 help="Group nodes by this attribute") 43 43 44 def make_subgraph(topelems, attr ):44 def make_subgraph(topelems, attrs): 45 45 """ 46 46 Take a list of topdl elements (Computers and Substrates ) and partition … … 58 58 else: m[a] = [ v] 59 59 60 if not attrs: return { } 61 60 62 sg = { } 63 attr, rest = attrs[0], attrs[1:] 61 64 for e in topelems: 62 65 if isinstance(e, topdl.Computer): … … 73 76 else: add_to_map(sg, 'default', e) 74 77 78 if rest: 79 for k in sg.keys(): 80 sg[k] = make_subgraph(sg[k], rest) 81 75 82 return sg 76 83 77 def gen_dot_topo(t, labels, dotfile, sg_attr=None): 78 """ 79 Write a dot description of the topology in t, a topdl.Topology to the open 80 file dotfile. the gen_image function below has already put some of that 81 file together. This function only generates the nodes and connections. If 82 labels is true, label the nodes. 83 """ 84 85 86 # The routine draws a circle for substrates with more than 2 interfaces 87 # connected to it, so this makes lists of each of those. 88 lans = [ s for s in t.substrates if len(s.interfaces) != 2] 89 links = [ s for s in t.substrates if len(s.interfaces) == 2] 90 91 # Break into subgraphs by the attribute of one's given 92 if sg_attr: sg = make_subgraph(t.elements + lans, sg_attr) 93 else: sg = { 'default': t.elements + lans } 94 84 def output_subgraphs(sg, dotfile): 95 85 96 86 # Construct subgraphs featurning nodes from those graphs … … 103 93 print >>dotfile, 'label="%s"' % sn 104 94 else: 105 print >>dotfile, 'subgraph "%s" {' % sn95 print >>dotfile, 'subgraph {' 106 96 print >>dotfile, 'color="#08c0f8"' 107 97 print >>dotfile, 'clusterrank="local"' 108 98 109 # For each node in the subgraph, output its representation 110 for i, n in enumerate(nodes): 111 if isinstance(n, topdl.Computer): 112 if n.name: 113 print >>dotfile, '\t"%s" [shape=box,style=filled,\\' % \ 114 n.name 115 else: 99 if isinstance(nodes, dict): output_subgraphs(nodes, dotfile) 100 elif isinstance(nodes, list): 101 # For each node in the subgraph, output its representation 102 for i, n in enumerate(nodes): 103 if isinstance(n, topdl.Computer): 104 if n.name: 105 print >>dotfile, \ 106 '\t"%s" [shape=box,style=filled,\\' % n.name 107 else: 108 print >>dotfile, \ 109 '\t"unnamed_node%d" [shape=box,style=filled,\\'\ 110 % i 116 111 print >>dotfile, \ 117 '\t"unnamed_node%d" [shape=box,style=filled,\\' % i 118 print >>dotfile, \ 119 '\t\tcolor=black,fillcolor="#60f8c0",regular=1]' 120 elif isinstance(n, topdl.Substrate): 121 print >>dotfile, '\t"%s" [shape=ellipse, style=filled,\\' % \ 122 n.name 123 print >>dotfile,'\t\tcolor=black,fillcolor="#80c0f8",regular=1]' 112 '\t\tcolor=black,fillcolor="#60f8c0",regular=1]' 113 elif isinstance(n, topdl.Substrate): 114 print >>dotfile, '\t"%s" [shape=ellipse, style=filled,\\' \ 115 % n.name 116 print >>dotfile,\ 117 '\t\tcolor=black,fillcolor="#80c0f8",regular=1]' 124 118 print >>dotfile, '}' 119 120 def gen_dot_topo(t, labels, dotfile, sg_attr): 121 """ 122 Write a dot description of the topology in t, a topdl.Topology to the open 123 file dotfile. the gen_image function below has already put some of that 124 file together. This function only generates the nodes and connections. If 125 labels is true, label the nodes. 126 """ 127 128 129 # The routine draws a circle for substrates with more than 2 interfaces 130 # connected to it, so this makes lists of each of those. 131 lans = [ s for s in t.substrates if len(s.interfaces) != 2] 132 links = [ s for s in t.substrates if len(s.interfaces) == 2] 133 134 # Break into subgraphs by the attribute of one's given 135 if sg_attr: sg = make_subgraph(t.elements + lans, sg_attr) 136 else: sg = { 'default': t.elements + lans } 137 138 139 output_subgraphs(sg, dotfile) 125 140 126 141 # Pull the edges out ot the lans and links … … 205 220 print >>dotfile, "graph G {" 206 221 if dpi: 207 print >>dotfile, '\tgraph [size="%i,%i", dpi="%i", ratio=fill];' \ 208 % (size, size, dpi) 222 print >>dotfile, \ 223 '\tgraph [size="%i,%i", dpi="%i", ratio=fill, compound="true"];' \ 224 % (size, size, dpi) 209 225 else: 210 print >>dotfile, '\tgraph [size="%i,%i", ratio=fill, clusterrank="local"compound="true"];' \ 211 % (size, size) 226 print >>dotfile, \ 227 '\tgraph [size="%i,%i", ratio=fill, compound="true"];' \ 228 % (size, size) 212 229 213 230 if labels:
Note: See TracChangeset
for help on using the changeset viewer.