FSTree() is a tree representing paths in a filesystem.  It has functions
for inserting paths and returning the paths it is storing.  A path is a
UNIX path: "/home/bjschuma" is the path to my home directory.
This commit is contained in:
Bryan Schumaker 2010-11-09 13:52:02 -05:00
parent 5cf8e8e639
commit 7ad74e6dca
1 changed files with 21 additions and 1 deletions

View File

@ -1,5 +1,7 @@
# Bryan Schumaker (11/06/2010)
from libsaria.path import sep
class Tree(dict):
def __init__(self, value = None):
#self.children = dict()
@ -24,7 +26,6 @@ class Tree(dict):
for res in child.walk():
yield [key] + res
def insert(self, path, values=[]):
path_part = path[0]
value = path_part
@ -38,3 +39,22 @@ class Tree(dict):
if len(path) > 1:
child.insert(path[1:], values)
class FSTree(Tree):
def __init__(self, value = None):
Tree.__init__(self, value)
def walk_paths(self):
for path in self.walk():
yield sep.join(path)
def insert_path(self, base, file = None):
path = base.split(sep)
self.insert_path_split(path, file)
def insert_path_split(self, base, file = None):
path = base
if file != None:
path += [file]
self.insert(path)