2019-04-27 18:50:04 +10:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
|
2019-04-28 08:26:43 +10:00
|
|
|
from typing import Dict
|
2019-04-27 18:50:04 +10:00
|
|
|
|
2019-04-28 08:26:43 +10:00
|
|
|
|
|
|
|
def graph_all(recipes: dict) -> None:
|
2019-04-27 18:50:04 +10:00
|
|
|
print("digraph G {")
|
|
|
|
for result, method in recipes.items():
|
2019-04-28 08:33:08 +10:00
|
|
|
for i in method[0]["input"]:
|
|
|
|
print(f"{i} -> {result}")
|
2019-04-27 18:50:04 +10:00
|
|
|
print("}")
|
|
|
|
|
|
|
|
|
2019-04-28 08:26:43 +10:00
|
|
|
def load_recipes(recipe_root: str) -> dict:
|
2019-04-27 18:50:04 +10:00
|
|
|
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
|
|
|
|
|
2019-04-28 08:26:43 +10:00
|
|
|
return recipes
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
root = os.path.dirname(__file__)
|
|
|
|
recipe_root = os.path.join(root, 'data', 'recipes')
|
|
|
|
graph_all(load_recipes(recipe_root))
|