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
|
|
|
|
|
|
|
|
2023-02-06 17:11:35 +00:00
|
|
|
def view(context: Context, scope: str | None = None, showExe: bool = True):
|
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-06 14:04:15 +00:00
|
|
|
g.attr('graph', splines='ortho', rankdir='BT')
|
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
|
|
|
|
|
|
|
|
fillcolor = "lightgrey" if instance.isLib() else "lightblue"
|
|
|
|
shape = "plaintext" if not scope == instance.manifest.id else 'box'
|
|
|
|
|
|
|
|
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
|
|
|
|
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 14:04:15 +00:00
|
|
|
g.edge(req, instance.manifest.id, arrowhead="none")
|
2023-02-06 11:36:23 +00:00
|
|
|
|
|
|
|
g.view(filename=f"{context.builddir()}/graph.gv")
|