curds: Switch library node to use the find / lookup allocate interface

And rescan paths when they're looked up again.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-06-02 20:13:09 -04:00
parent 84c77a25bc
commit 7455681202
3 changed files with 39 additions and 36 deletions

View File

@ -9,11 +9,6 @@ import os
library_thread = threadqueue.ThreadQueue()
class LibraryPlaylist(playlist.Playlist):
def __init__(self, path):
sort = [ "artist", "date", "album", "discnumber", "tracknumber" ]
playlist.Playlist.__init__(self, path, "folder-music", sort)
self.scan()
def __normalize__(self, name):
return os.path.abspath(name)
@ -38,12 +33,14 @@ class LibraryNode(node.PlaylistNode):
return os.path.abspath(name)
return node.PlaylistNode.__normalize__(self, name)
def alloc_node(self, path):
return LibraryPlaylist(path, "folder-music",
[ "artist", "date", "album", "discnumber", "tracknumber" ])
def lookup(self, path):
plist = node.PlaylistNode.lookup(self, os.path.abspath(path))
if plist == None:
plist = LibraryPlaylist(path)
self.insert_child(plist)
return plist
library = self.find_node(os.path.abspath(path))
library.scan()
return library
def join():

View File

@ -47,7 +47,7 @@ class PlaylistNode:
return self.__insert_node__(child, len(self.children))
def find_node(self, name):
node = self.lookup(name)
node = PlaylistNode.lookup(self, name)
if node == None:
node = self.alloc_node(name)
self.insert_child(node)

View File

@ -10,6 +10,7 @@ import time
import unittest
test_library = os.path.abspath("./trier/Test Library")
test_album = os.path.abspath("./trier/Test Album")
class TestLibraryPlaylist(unittest.TestCase):
def setUp(self):
@ -20,36 +21,41 @@ class TestLibraryPlaylist(unittest.TestCase):
def tearDownClass():
library.stop()
def test_playlist_library_init(self):
self.assertIsInstance(library.library_thread, threadqueue.ThreadQueue)
plist = library.LibraryPlaylist(test_library + "/")
self.assertIsInstance(plist, playlist.Playlist)
self.assertEqual(plist.name, test_library)
self.assertEqual(plist.icon, "folder-music")
self.assertEqual(plist.sort_order, [ "artist", "date", "album", "discnumber", "tracknumber" ])
def test_playlist_library_scan(self):
plist = library.LibraryPlaylist(test_library)
self.assertGreater(library.library_thread.qsize(), 0)
library.join()
self.assertEqual(len(plist), 1250)
self.assertEqual(plist.runtime(), "1 hour, 54 minutes, 35 seconds")
plist.scan()
library.join()
self.assertEqual(len(plist), 1250)
def test_playlist_library_node(self):
def test_library_node(self):
lnode = library.LibraryNode()
self.assertIsInstance(lnode, node.PlaylistNode)
self.assertEqual(lnode.name, "Libraries")
self.assertEqual(lnode.icon, "folder-music")
plist = lnode.lookup(test_library + "/")
def test_library_node_alloc(self):
lnode = library.LibraryNode()
plist = lnode.alloc_node(test_library)
self.assertIsInstance(plist, library.LibraryPlaylist)
self.assertEqual(plist.name, test_library)
self.assertEqual(plist.icon, "folder-music")
self.assertEqual(plist.sort_order,
[ "artist", "date", "album", "discnumber", "tracknumber"])
library.join()
self.assertEqual(len(plist), 0)
self.assertEqual(lnode.lookup(test_library), plist)
lnode.reset()
self.assertEqual(lnode.children, [ ])
def test_library_lookup(self):
lnode = library.LibraryNode()
plist = lnode.lookup(test_library)
self.assertEqual(lnode.n_children(), 1)
self.assertIsInstance(plist, library.LibraryPlaylist)
library.join()
self.assertEqual(len(plist), 1250)
self.assertEqual(lnode.lookup(test_library + "/"), plist)
plist = lnode.lookup(test_album)
self.assertEqual(lnode.n_children(), 2)
library.join()
self.assertEqual(len(plist), 12)
def test_library_thread_reset(self):
self.assertTrue(library.library_thread.is_alive())
library.stop()
self.assertFalse(library.library_thread.is_alive())
library.reset()
self.assertTrue(library.library_thread.is_alive())