From e70d787580421e84b5ed024d3362f095c0bc453f Mon Sep 17 00:00:00 2001 From: mungai-njoroge Date: Mon, 17 Jul 2023 11:30:05 +0300 Subject: [PATCH] misc --- app/lib/albumslib.py | 13 +++++++++---- app/lib/colorlib.py | 2 +- app/lib/watchdogg.py | 9 +++++++-- manage.py | 9 +++++++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/lib/albumslib.py b/app/lib/albumslib.py index d1b95da..a1c6909 100644 --- a/app/lib/albumslib.py +++ b/app/lib/albumslib.py @@ -2,9 +2,11 @@ Contains methods relating to albums. """ -from tqdm import tqdm +from alive_progress import alive_bar + from app.store.albums import AlbumStore from app.store.tracks import TrackStore +from app.logger import log def validate_albums(): @@ -17,6 +19,9 @@ def validate_albums(): album_hashes = {t.albumhash for t in TrackStore.tracks} albums = AlbumStore.albums - for album in tqdm(albums, desc="Validating albums"): - if album.albumhash not in album_hashes: - AlbumStore.remove_album(album) + with alive_bar(len(albums)) as bar: + log.info("Validating albums") + for album in albums: + if album.albumhash not in album_hashes: + AlbumStore.remove_album(album) + bar() diff --git a/app/lib/colorlib.py b/app/lib/colorlib.py index 2ebb3e7..6c143b8 100644 --- a/app/lib/colorlib.py +++ b/app/lib/colorlib.py @@ -53,7 +53,7 @@ class ProcessAlbumColors: """ def __init__(self) -> None: - albums = [a for a in AlbumStore.albums if len(a.colors) == 0] + albums = [a for a in AlbumStore.albums if a is None or len(a.colors) == 0] with SQLiteManager() as cur: try: diff --git a/app/lib/watchdogg.py b/app/lib/watchdogg.py index 21fa2f9..abcaa11 100644 --- a/app/lib/watchdogg.py +++ b/app/lib/watchdogg.py @@ -186,6 +186,7 @@ def add_track(filepath: str) -> None: extract_thumb(filepath, track.image) + def remove_track(filepath: str) -> None: """ Removes a track from the music dict. @@ -311,7 +312,11 @@ class Handler(PatternMatchingEventHandler): time.sleep(5) # Check the file size again - current_size = os.path.getsize(event.src_path) + try: + current_size = os.path.getsize(event.src_path) + except FileNotFoundError: + # File was deleted + return if current_size == previous_size: try: @@ -322,7 +327,7 @@ class Handler(PatternMatchingEventHandler): self.files_to_process_windows.remove(event.src_path) del self.file_sizes[event.src_path] except OSError: - # File is locked, skipping + # File is locked pass return diff --git a/manage.py b/manage.py index a789a3a..00fa80f 100644 --- a/manage.py +++ b/manage.py @@ -12,6 +12,7 @@ from app.setup import run_setup from app.start_info_logger import log_startup_info from app.utils.filesystem import get_home_res_path from app.utils.threading import background +from alive_progress import config_handler werkzeug = logging.getLogger("werkzeug") werkzeug.setLevel(logging.ERROR) @@ -47,7 +48,15 @@ def start_watchdog(): WatchDog().run() +def configure_alive_bar(): + """ + Sets the default alive bar settings. + """ + config_handler.set_global(spinner="classic", bar="classic2", enrich_print=False) + + if __name__ == "__main__": + configure_alive_bar() HandleArgs() log_startup_info() bg_run_setup()