libsaria: Fix library updating

I need to reindex and rebuild the tree on each update.  I also need to
notify the front-end that things have changed.
This commit is contained in:
Bryan Schumaker 2011-06-09 09:44:40 -04:00
parent e0ad57c541
commit 0e5bd0d908
5 changed files with 15 additions and 3 deletions

View File

@ -71,7 +71,6 @@ def make_library(path):
return
library.add_path(path)
library.update_lib()
libsaria.callbacks.library_updated()
def play_id(id):
global cur_id

View File

@ -1,5 +1,6 @@
# Bryan Schumaker (5 / 20 / 2011)
import libsaria
import library
import update
import tree
@ -20,6 +21,8 @@ index.reindex()
def update_lib():
update.update()
tree.make_tree()
index.reindex()
libsaria.callbacks.library_updated()
def reset():
library.reset()

View File

@ -23,6 +23,12 @@ for t in (splitt, lowert):
for c in t:
ttable[c] = t[c]
def reset():
global lib_index
global all_ids
lib_index = dict()
all_ids = set()
def format(text):
return text.translate(ttable).split()
@ -42,6 +48,7 @@ def add_tracks(tracks):
def reindex():
global matching
reset()
for src, tracks in library.lib_dict.iteritems():
add_tracks(tracks)
matching = all_ids

View File

@ -38,7 +38,7 @@ class Tree(dict):
child.insert(path[1:])
lib_tree = Tree()
lib_tree = None
def list_ids():
for id in lib_tree.walk():
@ -51,5 +51,7 @@ def add_tracks(tracks):
lib_tree.insert([artist, album, track.track, id])
def make_tree():
global lib_tree
lib_tree = Tree()
for src, tracks in library.lib_dict.iteritems():
add_tracks(tracks)

View File

@ -15,7 +15,6 @@ def song_id(path):
return stat(path).st_ino
def scan_path(path):
print "Scanning path:", path
file_map = dict()
for root, dir, files in walk(path):
for file in files:
@ -48,6 +47,8 @@ def update_path(path, tracks):
def update():
library.lock_library()
for path, lib in library.lib_dict.iteritems():
print "Updating path:", path
update_path(path, lib)
print "Done!"
library.save()
library.unlock_library()