Double linked trees
I have begun working on doubly-linked trees for use in collections.
This commit is contained in:
parent
6609e48d5c
commit
8221411ca2
|
@ -16,6 +16,8 @@ QUEUE = 2
|
|||
import collection
|
||||
library = collection.Collection()
|
||||
|
||||
library2 = collection.Collection2()
|
||||
|
||||
cur_lib_id = -1
|
||||
|
||||
def new_source(path, bg=True):
|
||||
|
@ -25,6 +27,13 @@ def new_source(path, bg=True):
|
|||
return 0
|
||||
return call("NEWSOURCE", library.scan, path)
|
||||
|
||||
def new_source2(path, bg=True):
|
||||
global library2
|
||||
path = expand(path)
|
||||
if not exists(path):
|
||||
return 0
|
||||
return call("NEWSOURCE2", library2.scan, path)
|
||||
|
||||
def walk_library():
|
||||
global library
|
||||
for track in library:
|
||||
|
|
|
@ -98,4 +98,36 @@ class Collection:
|
|||
#print e
|
||||
|
||||
|
||||
class Collection2:
|
||||
def __init__(self):
|
||||
self.tree = None
|
||||
|
||||
def save(self):
|
||||
from libsaria import data
|
||||
data.save((self.fs_tree), "DLTree_test", "")
|
||||
|
||||
def scan(self, path):
|
||||
print "Collection2 scanning %s" % path
|
||||
self.reset()
|
||||
self.update(path)
|
||||
self.save()
|
||||
self.fs_tree.disp()
|
||||
|
||||
def reset(self):
|
||||
from tree import DLTree
|
||||
self.fs_tree = DLTree()
|
||||
|
||||
def update(self, path):
|
||||
sep = libsaria.path.sep
|
||||
fs = self.fs_tree
|
||||
splitext = libsaria.path.splitext
|
||||
badfiles = set([".jpg", ".db", ".ape"])
|
||||
for root,dirs,files in libsaria.path.walk(path):
|
||||
root = root.strip(sep)
|
||||
split_root = root.split(sep)
|
||||
for file in files:
|
||||
ext = splitext(file)[1]
|
||||
if ext in badfiles:
|
||||
continue
|
||||
fs.insert(split_root + [file])
|
||||
#print split_root, file
|
||||
|
|
|
@ -59,3 +59,42 @@ class Tree(dict):
|
|||
node = Tree()
|
||||
self[tag] = node
|
||||
node.insert(tag_list[1:], tags, audio, filepath)
|
||||
|
||||
|
||||
class DLTree:
|
||||
def __init__(self, parent=None):
|
||||
self.parent = parent
|
||||
self.children = dict()
|
||||
|
||||
def disp(self, level=0):
|
||||
space = " " * level
|
||||
|
||||
for key,value in self.children.iteritems():
|
||||
if key.__class__ == str:
|
||||
print space, key
|
||||
value.disp(level+1)
|
||||
|
||||
#if len(self.children) == 0:
|
||||
# print self.get_path()
|
||||
|
||||
def get_path(self, child=None):
|
||||
if self.parent == None:
|
||||
return [self.children[child]]
|
||||
cmp = self.children.get(child, None)
|
||||
child = self
|
||||
path = self.parent.get_path(child)
|
||||
if cmp != None:
|
||||
path.append(cmp)
|
||||
return path
|
||||
|
||||
def insert(self, path):
|
||||
cmp = path[0]
|
||||
child = None
|
||||
try:
|
||||
child = self.children[cmp]
|
||||
except KeyError:
|
||||
child = DLTree(self)
|
||||
self.children[cmp] = child
|
||||
self.children[child] = cmp
|
||||
if len(path) > 1:
|
||||
child.insert(path[1:])
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
# Bryan Schumaker (10/1/2010)
|
||||
|
||||
from libsaria import collection
|
||||
|
||||
|
||||
collection.new_source2("~/Music/")
|
Loading…
Reference in New Issue