Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node:
- """
- Tree data-structure that has each directory as a node,
- each subdirectory as children and files as leaves.
- """
- def __init__(self, name, parent, children=[]):
- self.name = name
- self.parent = parent
- self.children = children
- def add_children(self, children):
- self.children.append(children)
- def search_name(self, name):
- if name == self.name:
- return self
- for child in self.children:
- if child.name == name:
- return child
- for child in self.children:
- found_node = child.search_name(name)
- if found_node is not None:
- return found_node
- return None
- def get_files(self, initials):
- print('---------------------------------------')
- for child in self.children:
- name = initials + os.sep+child.name
- # FIXME: What happens in case of empty directories?
- print('child:', child.name)
- print(' children:', child.children)
- for x in child.children:
- print('\t\t\t', x.name)
- if child.children == []:
- print('yielding')n
- yield name
- else:
- print('inside else')
- child.get_files(name)
- print('returned')
- def get_files_cd(self, initials):
- for child in self.children:
- name = initials+os.sep+child.name
- if child.children == []:
- yield name
Add Comment
Please, Sign In to add comment