From ea05907227eabbde1c68e53c343188063063ebf9 Mon Sep 17 00:00:00 2001 From: Sylvia Krech <40416079+Sylvia-Krech@users.noreply.github.com> Date: Sat, 4 May 2024 12:20:43 -0500 Subject: [PATCH 1/3] Fix for #119, Prompt for new location user if library cannot be saved --- tagstudio/src/qt/ts_qt.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index 18736fdd..8e206d78 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -555,7 +555,20 @@ class QtDriver(QObject): logging.info(f"Saving Library...") self.main_window.statusbar.showMessage(f"Saving Library...") start_time = time.time() - self.lib.save_library_to_disk() + # This might still be able to error, if the selected directory deletes in a race condition or something silly like that + # Hence the loop, but if this is considered overkill, thats fair. + while True: + try: + self.lib.save_library_to_disk() + break + # If the parent directory got moved, or deleted, prompt user for where to save. + except FileNotFoundError: + logging.info("Library parent directory not found, prompting user to select the directory") + dir = QFileDialog.getExistingDirectory( + None, "Library Location not found, please select location to save Library", "/", QFileDialog.ShowDirsOnly + ) + if dir not in (None, ""): + self.lib.library_dir = dir end_time = time.time() self.main_window.statusbar.showMessage( f"Library Saved! ({format_timespan(end_time - start_time)})" From 523f233f4ab38dcfc51f5756c05a7f4f6b731ae1 Mon Sep 17 00:00:00 2001 From: Sylvia Krech <40416079+Sylvia-Krech@users.noreply.github.com> Date: Sat, 4 May 2024 15:16:31 -0500 Subject: [PATCH 2/3] Ruff formatting --- tagstudio/src/qt/ts_qt.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index 8e206d78..5dc524dd 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -563,9 +563,14 @@ class QtDriver(QObject): break # If the parent directory got moved, or deleted, prompt user for where to save. except FileNotFoundError: - logging.info("Library parent directory not found, prompting user to select the directory") + logging.info( + "Library parent directory not found, prompting user to select the directory" + ) dir = QFileDialog.getExistingDirectory( - None, "Library Location not found, please select location to save Library", "/", QFileDialog.ShowDirsOnly + None, + "Library Location not found, please select location to save Library", + "/", + QFileDialog.ShowDirsOnly, ) if dir not in (None, ""): self.lib.library_dir = dir From 78ea0b3641802a549fed1528f6fb269d91fe2d20 Mon Sep 17 00:00:00 2001 From: Sylvia Krech <40416079+Sylvia-Krech@users.noreply.github.com> Date: Sat, 4 May 2024 16:45:38 -0500 Subject: [PATCH 3/3] close_library() fix --- tagstudio/src/qt/ts_qt.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index 5dc524dd..eabafdb5 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -551,12 +551,13 @@ class QtDriver(QObject): thread.wait() QApplication.quit() - def save_library(self): + def save_library(self, show_status=True): logging.info(f"Saving Library...") - self.main_window.statusbar.showMessage(f"Saving Library...") - start_time = time.time() - # This might still be able to error, if the selected directory deletes in a race condition or something silly like that - # Hence the loop, but if this is considered overkill, thats fair. + if show_status: + self.main_window.statusbar.showMessage(f"Saving Library...") + start_time = time.time() + # This might still be able to error, if the selected directory deletes in a race condition + # or something silly like that. Hence the loop, but if this is considered overkill, thats fair. while True: try: self.lib.save_library_to_disk() @@ -574,18 +575,18 @@ class QtDriver(QObject): ) if dir not in (None, ""): self.lib.library_dir = dir - end_time = time.time() - self.main_window.statusbar.showMessage( - f"Library Saved! ({format_timespan(end_time - start_time)})" - ) + if show_status: + end_time = time.time() + self.main_window.statusbar.showMessage( + f"Library Saved! ({format_timespan(end_time - start_time)})" + ) def close_library(self): if self.lib.library_dir: - # TODO: it is kinda the same code from "save_library"... - logging.info(f"Closing & Saving Library...") - self.main_window.statusbar.showMessage(f"Closed & Saving Library...") + logging.info(f"Closing Library...") + self.main_window.statusbar.showMessage(f"Closing & Saving Library...") start_time = time.time() - self.lib.save_library_to_disk() + self.save_library(show_status=False) self.settings.setValue("last_library", self.lib.library_dir) self.settings.sync()