@ -47,10 +47,13 @@
# rename plugin from "DeACSM" to "ACSM Input". BETA build, not a normal release!!
#
# v0.1.0: Continue work on renaming from "DeACSM" to "ACSM Input".
# The big version number jump is to make that name change clearer.
# The big version number jump is to make that name change clearer,
# and to support the "migration plugin" to rename the plugin.
# 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
@ -63,7 +66,6 @@ __version__ = PLUGIN_VERSION = ".".join([str(x)for x in PLUGIN_VERSION_TUPLE])
from calibre . utils . config import config_dir # type: ignore
from calibre . constants import islinux # type: ignore
import os , shutil , traceback , sys , time , io , random
import zipfile
@ -406,18 +408,82 @@ class ACSMInput(FileTypePlugin):
print ( " {0} v {1} : Error: Unsupported file type ... " . format ( PLUGIN_NAME , PLUGIN_VERSION ) )
return None
def is_blocked ( self ) :
import calibre_plugins . deacsm . prefs as prefs # type: ignore
deacsmprefs = prefs . ACSMInput_Prefs ( )
return deacsmprefs [ ' fulfillment_block_token ' ] != 0
def unblock ( self ) :
import calibre_plugins . deacsm . prefs as prefs # type: ignore
deacsmprefs = prefs . ACSMInput_Prefs ( )
my_token = deacsmprefs [ " fulfillment_block_token " ]
deacsmprefs . refresh ( )
if ( my_token == deacsmprefs [ " fulfillment_block_token " ] ) :
# Only unlock if this is my own lock
deacsmprefs . set ( " fulfillment_block_token " , 0 )
deacsmprefs . set ( " fulfillment_block_time " , 0 )
deacsmprefs . commit ( )
def wait_and_block ( self ) :
random_identifier = None
import calibre_plugins . deacsm . prefs as prefs # type: ignore
deacsmprefs = prefs . ACSMInput_Prefs ( )
while True :
deacsmprefs . refresh ( )
if deacsmprefs [ " fulfillment_block_token " ] == 0 :
random_identifier = random . getrandbits ( 64 )
#print("setting block token to %s" % (str(random_identifier)))
deacsmprefs . set ( " fulfillment_block_token " , random_identifier )
deacsmprefs . commit ( )
deacsmprefs . refresh ( )
if random_identifier != deacsmprefs [ " fulfillment_block_token " ] :
# print("we broke another thread's global token")
continue
deacsmprefs . set ( " fulfillment_block_time " , int ( time . time ( ) * 1000 ) )
#print("Obtained lock!")
return True
else :
# Token already exists, wait for it to finish ...
current_time = int ( time . time ( ) * 1000 )
saved_time = deacsmprefs [ " fulfillment_block_time " ]
if saved_time + 60000 < current_time :
# Already locked since 60s, assume error
print ( " {0} v {1} : Looks like the lock was stuck, removing lock {2} ... " . format ( PLUGIN_NAME , PLUGIN_VERSION , deacsmprefs [ " fulfillment_block_token " ] ) )
self . unblock ( )
time . sleep ( 0.02 )
continue
def run ( self , path_to_ebook ) :
# type: (str) -> str
try :
# This code gets called by Calibre with a path to the new book file.
# We need to check if it's an ACSM file
import calibre_plugins . deacsm . prefs as prefs # type: ignore
deacsmprefs = prefs . ACSMInput_Prefs ( )
if deacsmprefs [ ' allow_parallel_fulfillment ' ] == False :
self . wait_and_block ( )
print ( " {0} v {1} : Trying to parse file {2} " . format ( PLUGIN_NAME , PLUGIN_VERSION , os . path . basename ( path_to_ebook ) ) )
ext = os . path . splitext ( path_to_ebook ) [ 1 ] . lower ( )
if ( ext != " .acsm " ) :
print ( " {0} v {1} : That ' s not an ACSM, returning (is {2} instead)... " . format ( PLUGIN_NAME , PLUGIN_VERSION , ext ) )
self . unblock ( )
return path_to_ebook
# That's an ACSM.
@ -425,6 +491,7 @@ class ACSMInput(FileTypePlugin):
if not self . ADE_sanity_check ( ) :
print ( " {0} v {1} : ADE auth is missing or broken " . format ( PLUGIN_NAME , PLUGIN_VERSION ) )
self . unblock ( )
return path_to_ebook
@ -433,6 +500,7 @@ class ACSMInput(FileTypePlugin):
if not are_ade_version_lists_valid ( ) :
print ( " {0} v {1} : ADE version list mismatch, please open a bug report. " . format ( PLUGIN_NAME , PLUGIN_VERSION ) )
self . unblock ( )
return path_to_ebook
print ( " {0} v {1} : Try to fulfill ... " . format ( PLUGIN_NAME , PLUGIN_VERSION ) )
@ -543,9 +611,14 @@ class ACSMInput(FileTypePlugin):
# Return path - either the original one or the one modified by the other plugins.
self . unblock ( )
return rpl
self . unblock ( )
return path_to_ebook
except :
self . unblock ( )
traceback . print_exc ( )
return path_to_ebook