Implements graphviz output after a graph inspection.
This commit is contained in:
@ -1,22 +1,32 @@
|
||||
import json
|
||||
|
||||
import itertools
|
||||
|
||||
from bonobo.util.objects import get_name
|
||||
from bonobo.commands.run import read_file
|
||||
from bonobo.commands.run import read, register_generic_run_arguments
|
||||
from bonobo.constants import BEGIN
|
||||
|
||||
|
||||
def execute(file):
|
||||
graph, plugins, services = read_file(file)
|
||||
def execute(filename, module, install=False, quiet=False, verbose=False):
|
||||
graph, plugins, services = read(filename, module, install, quiet, verbose)
|
||||
|
||||
print('digraph {')
|
||||
print(' rankdir = LR;')
|
||||
print(' "BEGIN" [shape="point"];')
|
||||
|
||||
for i in graph.outputs_of(BEGIN):
|
||||
print(' "BEGIN" -> ' + json.dumps(get_name(graph.nodes[i])) + ';')
|
||||
print(' "BEGIN" -> ' + json.dumps(get_name(graph[i])) + ';')
|
||||
|
||||
for ix in graph.topologically_sorted_indexes:
|
||||
for iy in graph.outputs_of(ix):
|
||||
print(' {} -> {};'.format(
|
||||
json.dumps(get_name(graph[ix])),
|
||||
json.dumps(get_name(graph[iy]))
|
||||
))
|
||||
|
||||
print('}')
|
||||
|
||||
|
||||
def register(parser):
|
||||
import argparse
|
||||
parser.add_argument('file', type=argparse.FileType())
|
||||
register_generic_run_arguments(parser)
|
||||
return execute
|
||||
|
||||
@ -40,7 +40,7 @@ def _install_requirements(requirements):
|
||||
importlib.reload(site)
|
||||
|
||||
|
||||
def execute(filename, module, install=False, quiet=False, verbose=False):
|
||||
def read(filename, module, install=False, quiet=False, verbose=False):
|
||||
import runpy
|
||||
from bonobo import Graph, settings
|
||||
|
||||
@ -86,6 +86,12 @@ def execute(filename, module, install=False, quiet=False, verbose=False):
|
||||
filename, context.get(DEFAULT_SERVICES_ATTR)() if DEFAULT_SERVICES_ATTR in context else None
|
||||
)
|
||||
|
||||
return graph, plugins, services
|
||||
|
||||
|
||||
def execute(filename, module, install=False, quiet=False, verbose=False):
|
||||
graph, plugins, services = read(filename, module, install, quiet, verbose)
|
||||
|
||||
return bonobo.run(
|
||||
graph,
|
||||
plugins=plugins,
|
||||
|
||||
Reference in New Issue
Block a user