From f5e19f439125557360f9e156a0e75e95e37f805c Mon Sep 17 00:00:00 2001 From: Florian Bach Date: Sat, 6 May 2023 12:21:41 +0200 Subject: [PATCH] Bunch of fixes Fix #48 Fix SingleInstance in Calibre 4 Make plugin run in Calibre 3.48 --- calibre-plugin/__init__.py | 15 +++++++++++---- calibre-plugin/gui_main.py | 7 ++++++- calibre-plugin/prefs.py | 13 +++++++++++-- calibre-plugin/singleinstance_helper.py | 17 +++++++++++++++++ migration_plugin/__init__.py | 4 +--- 5 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 calibre-plugin/singleinstance_helper.py diff --git a/calibre-plugin/__init__.py b/calibre-plugin/__init__.py index 77a6e2d..fa35047 100644 --- a/calibre-plugin/__init__.py +++ b/calibre-plugin/__init__.py @@ -85,8 +85,10 @@ See the "LICENSE" file for a full copy of the GNU GPL v3. # Print useful warning if LicenseServiceCertificate download fails, # fix error with the loan list not being updated when importing multiple ACSMs at once, # fix bug with the GUI extension in non-English environments, -# add setting to choose between simultaneous (faster) or sequencial (more ADE-like) -# import of multiple ACSM files +# fix softlock when importing a large number of ACSM files at once, +# fix "account folder not found" error message on some clean installations, +# add experimental support for Calibre 3.48. + @@ -99,7 +101,12 @@ __version__ = PLUGIN_VERSION = ".".join([str(x)for x in PLUGIN_VERSION_TUPLE]) from calibre.utils.config import config_dir # type: ignore -from calibre.utils.lock import SingleInstance, singleinstance # type: ignore +from calibre.utils.lock import singleinstance # type: ignore + +try: + from calibre.utils.lock import SingleInstance # type: ignore +except: + from calibre_plugins.deacsm.singleinstance_helper import SingleInstance import os, shutil, traceback, sys, time, io, random import zipfile @@ -113,7 +120,7 @@ class ACSMInput(FileTypePlugin): supported_platforms = ['linux', 'osx', 'windows'] author = "Leseratte10" version = PLUGIN_VERSION_TUPLE - minimum_calibre_version = (4, 0, 0) + minimum_calibre_version = (3, 48, 0) file_types = set(['acsm']) on_import = True on_preprocess = True diff --git a/calibre-plugin/gui_main.py b/calibre-plugin/gui_main.py index 6817c20..11141b8 100644 --- a/calibre-plugin/gui_main.py +++ b/calibre-plugin/gui_main.py @@ -70,7 +70,12 @@ def create_menu_action_unique(ia, parent_menu, menu_text, image=None, tooltip=No class ActualACSMInputGUIExtension(InterfaceAction): name = "ACSM Input Plugin GUI Extension" - popup_type = QToolButton.ToolButtonPopupMode.InstantPopup + try: + popup_type = QToolButton.ToolButtonPopupMode.InstantPopup + except AttributeError: + # Needed for Calibre 3 + popup_type = 2 + action_type = 'global' action_spec = ("ACSM Input", None, "ACSM Input Plugin by Leseratte10", None) # Text, icon, tooltip, keyboard shortcut diff --git a/calibre-plugin/prefs.py b/calibre-plugin/prefs.py index 3818af8..d8a7576 100644 --- a/calibre-plugin/prefs.py +++ b/calibre-plugin/prefs.py @@ -15,7 +15,6 @@ import os import traceback from calibre.utils.config import JSONConfig, config_dir # type: ignore -from calibre.constants import iswindows # type: ignore class ACSMInput_Prefs(): @@ -54,8 +53,18 @@ class ACSMInput_Prefs(): success = True break - if not success: + # We did not find an account folder. See if we can create one ... + for f in ["DeACSM", "ACSMInput"]: + self.__maindir = os.path.join(self.__pluginsdir, f) + self.__accountdir = os.path.join(self.__maindir,"account") + if os.path.exists(self.__maindir): + os.mkdir(self.__accountdir) + self.deacsmprefs.defaults['path_to_account_data'] = self.__accountdir + success = True + break + + if not success: raise Exception("Why does the account folder not exist?") diff --git a/calibre-plugin/singleinstance_helper.py b/calibre-plugin/singleinstance_helper.py new file mode 100644 index 0000000..e848683 --- /dev/null +++ b/calibre-plugin/singleinstance_helper.py @@ -0,0 +1,17 @@ +from calibre.utils.lock import create_single_instance_mutex + +class SingleInstance: + + def __init__(self, name): + self.name = name + self.release_mutex = None + + def __enter__(self): + self.release_mutex = create_single_instance_mutex(self.name) + return self.release_mutex is not None + + def __exit__(self, *a): + if self.release_mutex is not None: + self.release_mutex() + self.release_mutex = None + diff --git a/migration_plugin/__init__.py b/migration_plugin/__init__.py index 3ed6b48..93c13c1 100644 --- a/migration_plugin/__init__.py +++ b/migration_plugin/__init__.py @@ -28,11 +28,9 @@ class DeACSMMigrationPlugin(InterfaceActionBase): version = (0, 0, 20) can_be_disabled = False - # This plugin will be auto-loaded from the ACSM Input plugin. It doesn't make sense for the user - # to disable it. If necessary, the menu bar button can be removed through the Calibre settings. type = "File type" - # Just so that the GUI extension shows up at the same place as the actual ACSM Input plugin. + # Just so that the migration extension shows up at the same place as the actual ACSM Input plugin. try: from calibre.customize import PluginInstallationType