From 481237dc778e812e9d0af0f30ebc4187c8a39ab9 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Fri, 23 Aug 2024 10:51:37 +0200 Subject: [PATCH] Fix for #3131 (Enable/Disable "Separate Book Files from Library" issue) --- cps/admin.py | 9 +++++++-- cps/config_sql.py | 20 -------------------- cps/embed_helper.py | 4 +--- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index 8c65e8589..ff34e8b8a 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -1716,6 +1716,13 @@ def _db_configuration_update_helper(): db_change = True except Exception as ex: return _db_configuration_result('{}'.format(ex), gdrive_error) + config.config_calibre_split = to_save.get('config_calibre_split', 0) == "on" + if config.config_calibre_split: + split_dir = to_save.get("config_calibre_split_dir") + if not os.path.exists(split_dir): + return _db_configuration_result(_("Books path not valid"), gdrive_error) + else: + _config_string(to_save, "config_calibre_split_dir") if db_change or not db_valid or not config.db_configured \ or config.config_calibre_dir != to_save["config_calibre_dir"]: @@ -1741,8 +1748,6 @@ def _db_configuration_update_helper(): calibre_db.update_config(config) if not os.access(os.path.join(config.config_calibre_dir, "metadata.db"), os.W_OK): flash(_("DB is not Writeable"), category="warning") - _config_string(to_save, "config_calibre_split_dir") - config.config_calibre_split = to_save.get('config_calibre_split', 0) == "on" calibre_db.update_config(config) config.save() return _db_configuration_result(None, gdrive_error) diff --git a/cps/config_sql.py b/cps/config_sql.py index 6a840af58..c810431b1 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -182,26 +182,6 @@ def __repr__(self): class ConfigSQL(object): # pylint: disable=no-member def __init__(self): - '''self.config_calibre_uuid = None - self.config_calibre_split_dir = None - self.dirty = None - self.config_logfile = None - self.config_upload_formats = None - self.mail_gmail_token = None - self.mail_server_type = None - self.mail_server = None - self.config_log_level = None - self.config_allowed_column_value = None - self.config_denied_column_value = None - self.config_allowed_tags = None - self.config_denied_tags = None - self.config_default_show = None - self.config_default_role = None - self.config_keyfile = None - self.config_certfile = None - self.config_rarfile_location = None - self.config_kepubifypath = None - self.config_binariesdir = None''' self.__dict__["dirty"] = list() def init_config(self, session, secret_key, cli): diff --git a/cps/embed_helper.py b/cps/embed_helper.py index 54db47ef6..f222bcd05 100644 --- a/cps/embed_helper.py +++ b/cps/embed_helper.py @@ -35,9 +35,7 @@ def do_calibre_export(book_id, book_format): my_env = os.environ.copy() if config.config_calibre_split: my_env['CALIBRE_OVERRIDE_DATABASE_PATH'] = os.path.join(config.config_calibre_dir, "metadata.db") - library_path = config.config_calibre_split_dir - else: - library_path = config.config_calibre_dir + library_path = config.get_book_path() opf_command = [calibredb_binarypath, 'export', '--dont-write-opf', '--with-library', library_path, '--to-dir', tmp_dir, '--formats', book_format, "--template", "{}".format(temp_file_name), str(book_id)]