Bunch of fixes

Fix #48
Fix SingleInstance in Calibre 4
Make plugin run in Calibre 3.48
This commit is contained in:
Florian Bach 2023-05-06 12:21:41 +02:00
parent 6a53617fde
commit f5e19f4391
5 changed files with 46 additions and 10 deletions

View File

@ -85,8 +85,10 @@ See the "LICENSE" file for a full copy of the GNU GPL v3.
# Print useful warning if LicenseServiceCertificate download fails, # Print useful warning if LicenseServiceCertificate download fails,
# fix error with the loan list not being updated when importing multiple ACSMs at once, # 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, # fix bug with the GUI extension in non-English environments,
# add setting to choose between simultaneous (faster) or sequencial (more ADE-like) # fix softlock when importing a large number of ACSM files at once,
# import of multiple ACSM files # 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.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 os, shutil, traceback, sys, time, io, random
import zipfile import zipfile
@ -113,7 +120,7 @@ class ACSMInput(FileTypePlugin):
supported_platforms = ['linux', 'osx', 'windows'] supported_platforms = ['linux', 'osx', 'windows']
author = "Leseratte10" author = "Leseratte10"
version = PLUGIN_VERSION_TUPLE version = PLUGIN_VERSION_TUPLE
minimum_calibre_version = (4, 0, 0) minimum_calibre_version = (3, 48, 0)
file_types = set(['acsm']) file_types = set(['acsm'])
on_import = True on_import = True
on_preprocess = True on_preprocess = True

View File

@ -70,7 +70,12 @@ def create_menu_action_unique(ia, parent_menu, menu_text, image=None, tooltip=No
class ActualACSMInputGUIExtension(InterfaceAction): class ActualACSMInputGUIExtension(InterfaceAction):
name = "ACSM Input Plugin GUI Extension" 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_type = 'global'
action_spec = ("ACSM Input", None, "ACSM Input Plugin by Leseratte10", None) action_spec = ("ACSM Input", None, "ACSM Input Plugin by Leseratte10", None)
# Text, icon, tooltip, keyboard shortcut # Text, icon, tooltip, keyboard shortcut

View File

@ -15,7 +15,6 @@ import os
import traceback import traceback
from calibre.utils.config import JSONConfig, config_dir # type: ignore from calibre.utils.config import JSONConfig, config_dir # type: ignore
from calibre.constants import iswindows # type: ignore
class ACSMInput_Prefs(): class ACSMInput_Prefs():
@ -54,6 +53,16 @@ class ACSMInput_Prefs():
success = True success = True
break 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: if not success:
raise Exception("Why does the account folder not exist?") raise Exception("Why does the account folder not exist?")

View File

@ -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

View File

@ -28,11 +28,9 @@ class DeACSMMigrationPlugin(InterfaceActionBase):
version = (0, 0, 20) version = (0, 0, 20)
can_be_disabled = False 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" 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: try:
from calibre.customize import PluginInstallationType from calibre.customize import PluginInstallationType