| 602 | tree = {} |
| 603 | |
| 604 | def add_to_tree(path_parts, items, current_node, full_path): |
| 605 | if len(path_parts) == 1: |
| 606 | folder_name = path_parts[0] |
| 607 | if folder_name not in current_node: |
| 608 | current_node[folder_name] = {} |
| 609 | if '__items__' not in current_node[folder_name]: |
| 610 | current_node[folder_name]['__items__'] = [] |
| 611 | current_node[folder_name]['__items__'].extend(items) |
| 612 | current_node[folder_name]['__path__'] = full_path |
| 613 | else: |
| 614 | folder_name = path_parts[0] |
| 615 | if folder_name not in current_node: |
| 616 | current_node[folder_name] = {} |
| 617 | |
| 618 | # The full path to this node so far |
| 619 | current_path = full_path.split(folder_name)[0] + folder_name |
| 620 | current_node[folder_name]['__path__'] = current_path |
| 621 | |
| 622 | add_to_tree(path_parts[1:], items, current_node[folder_name], full_path) |
| 623 | |
| 624 | # Enforce ordering |
| 625 | sections_to_emit = [] |