trackdb: Give TrackAllocators a function to list tracks in a library

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-06-22 16:42:20 -04:00
parent b3b39d2fc4
commit c5e317b737
2 changed files with 9 additions and 0 deletions

View File

@ -40,6 +40,12 @@ class TrackAllocator:
except Exception as e:
pass
def list_tracks(self, lib):
with self.lock:
for (id, track) in self.tracks.items():
if track.library ==lib:
yield track
def remove(self, track):
with self.lock:
del self.tracks[track.trackid]

View File

@ -46,6 +46,9 @@ class TestTrackAllocator(unittest.TestCase):
self.assertIsNone(alloc.allocate(lib, test_tracks / "No Such File"))
self.assertEqual(self.added, track2)
self.assertEqual([ t for t in alloc.list_tracks(lib) ], [ track, track2 ])
track.library = None
self.assertEqual([ t for t in alloc.list_tracks(lib) ], [ track2 ])
alloc.remove(track)
self.assertEqual(alloc[0], None)