From e7d9ff897d6c27ceba49d972c468c1d58054fe6c Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Wed, 10 Nov 2010 21:33:15 -0500 Subject: [PATCH] Library FSTrees and unique ids I now make a filesystem tree to store the library. In addition, I am using inode number to track songs. This should make it easier to detect moved files (inode number matches but path doesn't). --- libsaria/collection/library.py | 22 ++++++++++------------ libsaria/collection/track.py | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/libsaria/collection/library.py b/libsaria/collection/library.py index 15e281bb..69bb022e 100644 --- a/libsaria/collection/library.py +++ b/libsaria/collection/library.py @@ -1,5 +1,6 @@ # Bryan Schumaker (11/05/2010) +import os import tagpy import libsaria import string @@ -10,7 +11,6 @@ fs_tree = None tag_tree = None index = None tracks = None -next_id = None sources = None size = None visible = None @@ -27,7 +27,7 @@ for s in string.lowercase: ttable[ord(s)] = ord(s) - 32 def reset(): - from libsaria.trees import FSTree + from libsaria.trees import FSTree, DLFSTree from tree import DLTree from index import Index @@ -36,16 +36,14 @@ def reset(): global fs_tree global tag_tree global sources - global next_id global visible sources = FSTree() - fs_tree = DLTree() + fs_tree = DLFSTree() tag_tree = DLTree() index = Index() tracks = dict() - next_id = 0 size = 0 visible = set() #save() @@ -55,7 +53,6 @@ def load(): #global tag_tree #global index global tracks - global next_id global sources #global size #global songs @@ -65,14 +62,13 @@ def load(): #if objects == None or len(objects) != 6: reset() return - (sources, tracks, next_id) = objects - print next_id + (sources, tracks) = objects #(fs_tree, tag_tree, index, tracks, next_id, size) = objects libsaria.event.start("POSTLIBLOAD") def save(): global sources - libsaria.data.save( (sources, tracks, next_id), "library", ".lib") + libsaria.data.save( (sources, tracks), "library", ".lib") def walk(): return [] @@ -167,18 +163,20 @@ def scan(path): save() def insert_track(path, ref): - global next_id global tracks global ttable global fs_tree tags = ref.tag() audio = ref.audioProperties() + id = os.stat(path).st_ino track = Track(tags, audio) artist = tags.artist or u"Unknown Artist" album = tags.album or u"Unknown Album" title = tags.title or u"Unknown Title" - tracks[next_id] = track - next_id += 1 + fs = fs_tree.insert_path(path) + + track.fs = fs + tracks[id] = track def update_path(path): global badfiles diff --git a/libsaria/collection/track.py b/libsaria/collection/track.py index d9a46209..a8b9c0ca 100644 --- a/libsaria/collection/track.py +++ b/libsaria/collection/track.py @@ -20,5 +20,5 @@ class Track: else: self.lenstr = lenstr - #self.fs = None + self.fs = None #self.tags = None