cutekit/osdk/graph.py

56 lines
2.3 KiB
Python
Raw Normal View History

2023-02-06 11:36:23 +00:00
from osdk.context import Context
2023-02-06 17:11:35 +00:00
from osdk import vt100
2023-02-06 11:36:23 +00:00
def view(context: Context, scope: str | None = None, showExe: bool = True, showDisabled: bool = False):
2023-02-08 09:50:43 +00:00
from graphviz import Digraph
2023-02-06 11:36:23 +00:00
g = Digraph(context.target.id, filename='graph.gv')
2023-02-06 12:25:12 +00:00
2023-02-10 20:58:46 +00:00
g.attr('graph', splines='ortho', rankdir='BT', ranksep='1.5')
2023-02-06 11:36:23 +00:00
g.attr('node', shape='ellipse')
2023-02-06 17:11:35 +00:00
g.attr(
'graph', label=f"<<B>{scope or 'Full Dependency Graph'}</B><BR/>{context.target.id}>", labelloc='t')
scopeInstance = None
if scope is not None:
scopeInstance = context.componentByName(scope)
2023-02-06 11:36:23 +00:00
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 17:11:35 +00:00
if scopeInstance is not None and \
instance.manifest.id != scope and \
instance.manifest.id not in scopeInstance.resolved:
continue
if instance.enabled:
fillcolor = "lightgrey" if instance.isLib() else "lightblue"
shape = "plaintext" if not scope == instance.manifest.id else 'box'
2023-02-06 17:11:35 +00:00
g.node(instance.manifest.id, f"<<B>{instance.manifest.id}</B><BR/>{vt100.wordwrap(instance.manifest.decription, 40,newline='<BR/>')}>",
shape=shape, style="filled", fillcolor=fillcolor)
2023-02-06 12:25:12 +00:00
for req in instance.manifest.requires:
g.edge(instance.manifest.id, req)
2023-02-06 11:36:23 +00:00
for req in instance.manifest.provides:
2023-02-10 20:58:46 +00:00
isChosen = context.target.routing.get(
req, None) == instance.manifest.id
g.edge(req, instance.manifest.id, arrowhead="none", color=(
"blue" if isChosen else "black"))
elif showDisabled:
g.node(instance.manifest.id, f"<<B>{instance.manifest.id}</B><BR/>{vt100.wordwrap(instance.manifest.decription, 40,newline='<BR/>')}<BR/><BR/><I>{vt100.wordwrap(instance.disableReason, 40,newline='<BR/>')}</I>>",
shape="plaintext", style="filled", fontcolor="#999999", fillcolor="#eeeeee")
for req in instance.manifest.requires:
g.edge(instance.manifest.id, req, color="#aaaaaa")
for req in instance.manifest.provides:
g.edge(req, instance.manifest.id,
arrowhead="none", color="#aaaaaa")
2023-02-06 11:36:23 +00:00
2023-02-21 16:33:38 +00:00
g.view(filename=os.path.join(context.builddir(), "graph.gv"))