scanner: Fix scanner.update_library() function

We were scheduling the CheckTask, but not following up with a
DirectoryTask to scan for new files. I use this function during the
Gtk.Application startup to automatically update the libraries.

Implements #31 (Automatically update the database during startup)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-12-27 16:52:20 -05:00
parent 295202443f
commit 328dce0be2
3 changed files with 5 additions and 0 deletions

View File

@ -16,6 +16,8 @@ class Application(Gtk.Application):
def do_startup(self):
Gtk.Application.do_startup(self)
self.add_window(ui.window.Window())
for i in range(db.library.Table.get_n_items()):
scanner.update_library(db.library.Table.get_item(i))
def do_activate(self):
for window in self.get_windows():

View File

@ -31,6 +31,7 @@ def commit():
def update_library(lib):
Queue.push(task.CheckSchedulerTask(lib))
Queue.push(task.DirectoryTask(lib, lib.path))
def remove_library(lib):
Queue.push(task.RemoveLibrarySchedulerTask(lib))

View File

@ -20,6 +20,8 @@ class TestScanner(unittest.TestCase):
scanner.update_library(lib)
self.assertIsInstance(scanner.Queue.tasks[0],
scanner.task.CheckSchedulerTask)
self.assertIsInstance(scanner.Queue.tasks[1],
scanner.task.DirectoryTask)
def test_remove_library(self):
lib = db.library.Table.find(test_album)