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