Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from altgraph import Dot
# TODO: add a style for commands and nodes
def node_visitor(node):
"""
Return a custom style for a node.
For file nodes: ellipses, with different colors based on devel/source,
deployed/target and paths (such as sockets, pipes, existing or not) or
circle for non- existing things like pipes/sockets? for command nodes:
boxes, with different colors (such as lighter for pure forkers?).
"""
# return a styles dict based on the node type or an empty dict for the
# default (ellipse, white)
return {}
dot = Dot.Dot(graph, nodevisitor=node_visitor)
# redirect temp to a real temp to avoid junk file creation
import tempfile
dot.temp_dot = os.path.join(tempfile.mkdtemp(), dot.temp_dot)
# render left to right
dot.style(rankdir='LR')
# save as dot or image/pdf
if file_type == 'dot':
logger.info('Saving dot file ...')
dot.save_dot(file_name)
return file_name
else:
logger.info('Building and saving graphic file ...')
dot.save_img(file_name=file_name, file_type=file_type, mode=mode)
try:
n0 = name.get_name()
except:
n0 = str(name)
n1 = str(n0).replace('"', '')
n2 = n1.replace("\n", '')
return n2
import altgraph
from altgraph import Graph, Dot
graph = Graph.Graph()
for i, v in enumerate(g.get_vertices()):
graph.add_node(i) # , node_data=g.get_vertex_name(v)
for i, v in enumerate(g.get_vertices()):
for n in g.get_out_neighbors(v):
graph.add_edge(v, n)
dot = Dot.Dot(graph) # , graph_type="digraph"
for i, v in enumerate(g.get_vertices()):
dot.node_style(i, label=clean(g.get_vertex_name(v)))
dot.display()
def make_dot(graph):
"""Convert the graph to a dot file.
Node and edge styles is obtained from the corresponding data.
Args:
graph (Graph.Graph): The graph.
Returns:
Dot.Dot: The dot file generator.
"""
dot = Dot.Dot(graph, graphtype="digraph")
dot.style(overlap=False, bgcolor="transparent")
for node in graph:
node_data = graph.node_data(node)
shape = ("circle" if node_data.type is "vertex" else "doublecircle")
color, fillcolor = dict(missing=("red", "moccasin"),
outdated=("forestgreen", "lightblue")
).get(node_data.status, ("black", "white"))
dot.node_style(node, shape=shape,
style="filled", fillcolor=fillcolor, color=color)
for edge, edge_data, head, tail in (graph.describe_edge(edge)
for edge in graph.edge_list()):
section = edge_data.section
color = dict(fetch="forestgreen",
extract="darkgreen",
build="blue",
runtime="red",