cutekit/osdk/graph.py

26 lines
839 B
Python
Raw Normal View History

2023-02-06 11:36:23 +00:00
from graphviz import Digraph
from osdk.context import Context
2023-02-06 12:25:12 +00:00
def view(context: Context, showExe: bool = False):
2023-02-06 11:36:23 +00:00
g = Digraph(context.target.id, filename='graph.gv')
2023-02-06 12:25:12 +00:00
g.attr('graph', splines='ortho', concentrate='true')
2023-02-06 11:36:23 +00:00
g.attr('node', shape='ellipse')
for instance in context.instances:
2023-02-06 12:25:12 +00:00
if not instance.isLib() and not showExe:
2023-02-06 11:36:23 +00:00
continue
2023-02-06 12:25:12 +00:00
2023-02-06 11:36:23 +00:00
g.node(instance.manifest.id, f"<<B>{instance.manifest.id}</B><BR/>{instance.manifest.decription}>",
2023-02-06 12:25:12 +00:00
shape="plaintext", style="filled", fillcolor="lightgrey" if instance.isLib() else "lightblue")
2023-02-06 11:36:23 +00:00
for req in instance.manifest.requires:
2023-02-06 12:25:12 +00:00
g.edge(instance.manifest.id, req)
2023-02-06 11:36:23 +00:00
for req in instance.manifest.provides:
2023-02-06 12:25:12 +00:00
g.edge(req, instance.manifest.id)
2023-02-06 11:36:23 +00:00
g.view(filename=f"{context.builddir()}/graph.gv")