Commit 5435cca9 authored by Vincent Stehlé's avatar Vincent Stehlé
Browse files rework key_tree_2_md

Simplify the printing by group, to help debugging. As a bonus, this is more
Signed-off-by: Vincent Stehlé's avatarVincent Stehlé <>
parent 6410b6de
...@@ -192,27 +192,23 @@ def seq_parser(file): ...@@ -192,27 +192,23 @@ def seq_parser(file):
return temp_dict return temp_dict
# group items by key, and print by key # Print items by "group"
# we slowly iterate through the list, group and print groups def key_tree_2_md(input_list, file):
def key_tree_2_md(input_list, file, key): h = {}
# make a copy so we don't destroy the first list.
temp_list = input_list.copy() # Bin by group
while temp_list: for t in input_list:
test_dict = temp_list.pop() g = t['group']
found, not_found = [test_dict], []
# go through whole list looking for key match if g not in h:
while temp_list: h[g] = []
next_dict = temp_list.pop()
# if match add to found h[g].append(t)
if next_dict[key] == test_dict[key]:
found.append(next_dict) # Print each group
# else not found for g in sorted(h.keys()):
else: file.write("### " + g)
not_found.append(next_dict) dict_2_md(h[g], file)
# start over with found items removed
temp_list = not_found
file.write("### " + test_dict[key])
dict_2_md(found, file)
# generic writer, takes a list of dicts and turns the dicts into an MD table. # generic writer, takes a list of dicts and turns the dicts into an MD table.
...@@ -737,7 +733,7 @@ if __name__ == '__main__': ...@@ -737,7 +733,7 @@ if __name__ == '__main__':
for k in sorted(res_keys_np): for k in sorted(res_keys_np):
resultfile.write("## {}. {} by group\n\n".format(n, k.title())) resultfile.write("## {}. {} by group\n\n".format(n, k.title()))
key_tree_2_md(bins[k], resultfile, "group") key_tree_2_md(bins[k], resultfile)
n += 1 n += 1
# Generate yaml config template if requested # Generate yaml config template if requested
Markdown is supported
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