Skip to content
Snippets Groups Projects
Commit 145826a2 authored by Virgile Gerecke's avatar Virgile Gerecke :metal:
Browse files

Upgraded version of tree display

parent 02869bca
No related merge requests found
Pipeline #12806 passed with stage
in 19 seconds
......@@ -6,5 +6,7 @@ unittest:
tags:
- python3.5
script:
- pip3 install -r requirements.txt
- python3 verify.py
- python3 display.py
import json
from pptree import *
from anytree import Node, RenderTree
#from anytree.exporter import DotExporter
content = json.loads(open('help.json').read())
d = {}
......@@ -8,11 +9,11 @@ def add_child(key, path):
global d
item = content[key]
if 'action' in item:
n = Node(item["action"], d[path])
n = Node(item["action"], parent=d[path])
return None
else:
for option in item['options']:
n = Node(item["title"], d[path])
n = Node("{} ({})".format(content[option]["title"],content[option]["description"]), parent=d[path])
n_path = path + "-" + option
d[n_path] = n
add_child(option, n_path)
......@@ -21,4 +22,7 @@ root = Node("root")
d["root"]=root
add_child("root", "root")
print_tree(root)
for pre, fill, node in RenderTree(root):
print("%s%s" % (pre, node.name))
#DotExporter(root).to_picture("help.png")
anytree==2.4.3
six==1.11.0
......@@ -31,7 +31,7 @@ def run(key, content, path):
item=content[key]
if 'action' in item:
path.append(item['action'])
print(path)
# print(path)
return None
else:
for option in item['options']:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment