FSTree()
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:
parent
5cf8e8e639
commit
7ad74e6dca
|
@ -1,5 +1,7 @@
|
||||||
# Bryan Schumaker (11/06/2010)
|
# Bryan Schumaker (11/06/2010)
|
||||||
|
|
||||||
|
from libsaria.path import sep
|
||||||
|
|
||||||
class Tree(dict):
|
class Tree(dict):
|
||||||
def __init__(self, value = None):
|
def __init__(self, value = None):
|
||||||
#self.children = dict()
|
#self.children = dict()
|
||||||
|
@ -24,7 +26,6 @@ class Tree(dict):
|
||||||
for res in child.walk():
|
for res in child.walk():
|
||||||
yield [key] + res
|
yield [key] + res
|
||||||
|
|
||||||
|
|
||||||
def insert(self, path, values=[]):
|
def insert(self, path, values=[]):
|
||||||
path_part = path[0]
|
path_part = path[0]
|
||||||
value = path_part
|
value = path_part
|
||||||
|
@ -38,3 +39,22 @@ class Tree(dict):
|
||||||
if len(path) > 1:
|
if len(path) > 1:
|
||||||
child.insert(path[1:], values)
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue