Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 """Provides functions to produce dotcode which represents the capability graph
00037 """
00038
00039 from qt_dotgraph.pydotfactory import PydotFactory
00040
00041
00042 def generate_dotcode_from_capability_info(spec_index, running_providers):
00043 dotcode_factory = PydotFactory()
00044 dotgraph = dotcode_factory.get_graph(rankdir="BT")
00045 interface_graphs = {}
00046
00047 for name in spec_index.interfaces:
00048 providers = [k for k, v in spec_index.providers.items() if v.implements == name]
00049
00050 if providers:
00051 interface_graphs[name] = dotcode_factory.add_subgraph_to_graph(dotgraph, str(name) + "_group", subgraphlabel='')
00052
00053 graph = interface_graphs.get(name, dotgraph)
00054 dotcode_factory.add_node_to_graph(graph, nodename=str(name), shape="box")
00055
00056 for name, interface in spec_index.semantic_interfaces.items():
00057 providers = [k for k, v in spec_index.providers.items() if v.implements == name]
00058
00059 if providers:
00060 interface_graphs[name] = dotcode_factory.add_subgraph_to_graph(dotgraph, str(name) + "_group", subgraphlabel='')
00061 graph = interface_graphs.get(name, dotgraph)
00062
00063 dotcode_factory.add_node_to_graph(graph, nodename=str(name), shape="box")
00064
00065 if interface.redefines in spec_index.interfaces:
00066 dotcode_factory.add_edge_to_graph(dotgraph, str(name), str(interface.redefines), label="redefines")
00067
00068 interfaces = dict(spec_index.interfaces)
00069 interfaces.update(spec_index.semantic_interfaces)
00070 for name, provider in spec_index.providers.items():
00071
00072 graph = interface_graphs[provider.implements]
00073
00074 default_provider = interfaces[provider.implements].default_provider
00075 provider_name = name
00076
00077 if default_provider != 'unknown' and default_provider == name:
00078 provider_name += " (default)"
00079
00080 if name in running_providers:
00081 dotcode_factory.add_node_to_graph(graph, nodename=str(name), nodelabel=str(provider_name), shape="ellipse", color="green")
00082
00083 else:
00084 dotcode_factory.add_node_to_graph(graph, nodename=str(name), nodelabel=str(provider_name), shape="ellipse")
00085
00086 for dep, relationship in provider.dependencies.items():
00087 if relationship.preferred_provider is not None:
00088 dotcode_factory.add_edge_to_graph(dotgraph, str(name), str(relationship.preferred_provider), label="requires")
00089 elif spec_index.interfaces[relationship.capability_name].default_provider != 'unknown':
00090 dotcode_factory.add_edge_to_graph(dotgraph, str(name), str(spec_index.interfaces[relationship.capability_name].default_provider), label="requires")
00091 return dotcode_factory.create_dot(dotgraph)