From 0e5bd0d9085dcee332f5de8d4e8f75219ae4ce40 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Thu, 9 Jun 2011 09:44:40 -0400 Subject: [PATCH] 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. --- libsaria/sources/__init__.py | 1 - libsaria/sources/library/__init__.py | 3 +++ libsaria/sources/library/index.py | 7 +++++++ libsaria/sources/library/tree.py | 4 +++- libsaria/sources/library/update.py | 3 ++- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libsaria/sources/__init__.py b/libsaria/sources/__init__.py index 900aa834..ba261d07 100644 --- a/libsaria/sources/__init__.py +++ b/libsaria/sources/__init__.py @@ -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 diff --git a/libsaria/sources/library/__init__.py b/libsaria/sources/library/__init__.py index 0b3e117e..a6dbf0d4 100644 --- a/libsaria/sources/library/__init__.py +++ b/libsaria/sources/library/__init__.py @@ -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() diff --git a/libsaria/sources/library/index.py b/libsaria/sources/library/index.py index 4fd2d256..08109c64 100644 --- a/libsaria/sources/library/index.py +++ b/libsaria/sources/library/index.py @@ -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 diff --git a/libsaria/sources/library/tree.py b/libsaria/sources/library/tree.py index 0f96df74..5ce5d73a 100644 --- a/libsaria/sources/library/tree.py +++ b/libsaria/sources/library/tree.py @@ -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) diff --git a/libsaria/sources/library/update.py b/libsaria/sources/library/update.py index 0acaf5e8..deccb2a7 100644 --- a/libsaria/sources/library/update.py +++ b/libsaria/sources/library/update.py @@ -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()