From 0b228edf1529e048671e7e254bb7f2c5e0f0b4c2 Mon Sep 17 00:00:00 2001 From: Florian Bach Date: Wed, 7 Aug 2024 09:46:30 +0200 Subject: [PATCH] Fix plugin when libcrypto override variable is not set --- calibre-plugin/__init__.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/calibre-plugin/__init__.py b/calibre-plugin/__init__.py index 0568995..342876c 100644 --- a/calibre-plugin/__init__.py +++ b/calibre-plugin/__init__.py @@ -285,18 +285,23 @@ class ACSMInput(FileTypePlugin): # Okay, now all the modules are available, import the Adobe modules. + + # On some systems, like NixOS, the path to libcrypto and libssl + # isn't autodetected correctly. To fix this, allow overriding + # these paths using environment variables. # Crucial to import first, as libadobe imports oscrypto as well - libcrypto_path = os.environ["ACSM_LIBCRYPTO"] - libssl_path = os.environ["ACSM_LIBSSL"] + libcrypto_path = os.getenv("ACSM_LIBCRYPTO", None) + libssl_path = os.getenv("ACSM_LIBSSL", None) - if os.path.exists(libcrypto_path) and os.path.exists(libssl_path): - import oscrypto + if libcrypto_path is not None and libssl_path is not None: + if os.path.exists(libcrypto_path) and os.path.exists(libssl_path): + import oscrypto # type: ignore - oscrypto.use_openssl( - libcrypto_path = libcrypto_path, - libssl_path = libssl_path, - ) + oscrypto.use_openssl( + libcrypto_path = libcrypto_path, + libssl_path = libssl_path, + ) from libadobe import createDeviceKeyFile, update_account_path, sendHTTPRequest