#!/usr/bin/env python # ipc connections: (from, to, number) ipcs = [ ('c1scx', 'c1lsc', 1), ('c1scy', 'c1lsc', 1), ('c1oaf', 'c1lsc', 8), ('c1scx', 'c1ass', 1), ('c1scy', 'c1ass', 1), ('c1lsc', 'c1ass', 12), ('c1ioo', 'c1ass', 3), ('c1lsc', 'c1oaf', 7), ('c1pem', 'c1oaf', 21), ('c1mcs', 'c1oaf', 7), ('c1lsc', 'c1sus', 5), ('c1ass', 'c1sus', 10), ('c1scx', 'c1sus', 1), ('c1scy', 'c1sus', 1), ('c1ioo', 'c1mcs', 7), ('c1lsc', 'c1mcs', 1), ('c1als', 'c1mcs', 1), ('c1mcs', 'c1ioo', 4), ('c1lsc', 'c1scx', 1), ('c1ass', 'c1scx', 2), ('c1sus', 'c1scx', 1), ('c1lsc', 'c1scy', 1), ('c1ass', 'c1scy', 2), ('c1sus', 'c1scy', 1), ] # models on hosts hosts = { 'c1lsc': ['c1lsc', 'c1ass', 'c1oaf'], 'c1sus': ['c1sus', 'c1mcs', 'c1pem'], 'c1ioo': ['c1ioo', 'c1als'], 'c1iscex': ['c1scx'], 'c1iscey': ['c1scy'], } # dictionary of hosts for models # FIXME: this should be generated from the /etc/rtstab def m2h(hosts): m2h = {} for host, models in hosts.items(): for model in models: m2h[model] = host return m2h models = m2h(hosts) ################################################### def dotplot(graph, outfile=None): import subprocess import tempfile if outfile: graph.write(outfile, format=os.path.splitext(outfile)[1].strip('.')) else: format = 'svg' suffix = '.%s' % format viewer = 'xdg-open' try: with tempfile.NamedTemporaryFile(suffix=suffix, delete=True) as f: graph.write(f.name, format=format) subprocess.call([viewer, f.name]) except KeyboardInterrupt: sys.exit() ################################################### import os import sys import pydot import networkx as nx import matplotlib.pyplot as plt try: outfile = sys.argv[1] except IndexError: outfile = None colors = {'c1lsc': 'blue', 'c1sus': 'green', 'c1ioo': 'red', 'c1iscex': 'cyan', 'c1iscey': 'magenta'} G = nx.DiGraph() for edge in ipcs: h0 = models[edge[0]] h1 = models[edge[1]] print h0, h1, edge[2] G.add_edge(h0, h1) if 'weight' not in G[h0][h1]: G[h0][h1]['weight'] = edge[2] else: G[h0][h1]['weight'] += edge[2] G[h0][h1]['label'] = G[h0][h1]['weight'] #G[h0][h1]['penwidth'] = G[h0][h1]['weight'] gg = nx.to_pydot(G) dotplot(gg, outfile)