Skip to content
Snippets Groups Projects
display.py 709 B
Newer Older
Virgile Gerecke's avatar
Virgile Gerecke committed
import json
from anytree import Node, RenderTree
#from anytree.exporter import DotExporter
Virgile Gerecke's avatar
Virgile Gerecke committed

content = json.loads(open('help.json').read())
d  = {}

def add_child(key, path):
  global d
  item = content[key]
  if 'action' in item:
    n = Node(item["action"], parent=d[path])
Virgile Gerecke's avatar
Virgile Gerecke committed
    return None
  else:
    for option in item['options']:
      n = Node("{} ({})".format(content[option]["title"],content[option]["description"]), parent=d[path])
Virgile Gerecke's avatar
Virgile Gerecke committed
      n_path = path + "-" + option
      d[n_path] = n
      add_child(option, n_path)

root = Node("root")
d["root"]=root
add_child("root", "root")

for pre, fill, node in RenderTree(root):
  print("%s%s" % (pre, node.name))

#DotExporter(root).to_picture("help.png")