graph: add graphviz script
This commit is contained in:
parent
fc1e56dc8a
commit
b8a0da6898
32
graph.py
Executable file
32
graph.py
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import json
|
||||||
|
import typing
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def as_graphviz(recipes: dict):
|
||||||
|
print("digraph G {")
|
||||||
|
for result, method in recipes.items():
|
||||||
|
for variation in method:
|
||||||
|
for input in variation["input"]:
|
||||||
|
print(f"{input} -> {result}")
|
||||||
|
print("}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
root = os.path.dirname(__file__)
|
||||||
|
recipe_root = os.path.join(root, 'data', 'recipes')
|
||||||
|
|
||||||
|
recipes = dict()
|
||||||
|
|
||||||
|
for dirname, dirs, files in os.walk(recipe_root):
|
||||||
|
for f in files:
|
||||||
|
path = os.path.join(dirname, f)
|
||||||
|
name, _ = os.path.splitext(f)
|
||||||
|
with open(path, 'r') as src:
|
||||||
|
variations = json.load(src)
|
||||||
|
|
||||||
|
recipes[name] = variations
|
||||||
|
|
||||||
|
as_graphviz(recipes)
|
Loading…
Reference in New Issue
Block a user