def create_tree(table: dict,
root: str,
mark: str,
f_pid: str="pid",
f_id: str="id",
f_label: str="item",
f_ctime: str="ctime",
v_none: str="null",
colors: bool=False) -> str:
"""
Creates the ascii checkpoint tree.
Args:
table: List of checkpoints as a table.
root: Root label of the tree.
mark: Current snapshot name. Mark the element with an '*'
f_pid: Field of the table that contains the parent id of the node.
f_id: Field of the table that contains the id of the node.
f_label: Field with the label of the node.
f_ctime: Field with the timestamp creation date.
v_none: Value to be used for empty fields.
colors: Use colors in the tree output.
Returns:
A string containing the tree of snapshots
"""
items = [(c[f_pid], c[f_id]) for c in table]
tree = {root: OD()}
inserted = []
while [x[1] for x in items if x[1] not in inserted]:
for parent, item in items:
if parent == v_none:
parent = root
inserts = walk(tree, parent, item)
inserted.extend(list(inserts))
tr = LeftAligned()
tr_tree = tr(tree)
for cell in table:
if cell[f_label] == mark:
cell[f_label] = "{}*".format(cell[f_label])
if colors:
tr_tree = tr_tree.replace(cell[f_id],
"{}{} {}({}){}".format(
Fore.LIGHTWHITE_EX,
cell[f_label],
Fore.CYAN,
convert_dt(cell[f_ctime]),
Fore.RESET))
else:
tr_tree = tr_tree.replace(cell[f_id],
"{} ({})".format(
cell[f_label],
convert_dt(cell[f_ctime])))
return tr_tree
评论列表
文章目录