Пример #1
0
        def iterate(node_: FileNode) -> Iterable:
            prefix_tabs = (node_.get_depth()) * '\t'
            if node_.is_file():
                yield f"{prefix_tabs}<li>{node_.get_filename()}</li>"
            else:
                yield f"{prefix_tabs}\t<li>{node_.get_filename()}</li>"
                yield f"{prefix_tabs}\t<ul>"

            children = node_.get_children()
            for child_node in children:
                yield from iterate(child_node)

            if not node_.is_file():
                yield f"{prefix_tabs}\t</ul>"
Пример #2
0
 def traverse(node: FileNode):
     if node.get_root() is None or node.get_relative_path() is None:
         raise ValueError("To reproduce given tree in file system, every node much have relative path,"
                          "since relative path is calculated with root path, FileNode has to be initialized"
                          "with root path. both root and relative path must be available")
     path = target_dir / node.get_relative_path()
     if node.is_dir():
         path.mkdir(parents=True, exist_ok=True)
     elif node.is_file():
         path.touch(exist_ok=True)
     if node.get_children():
         for child_node in node.get_children():
             traverse(child_node)