From ef67dbd204b024e4e6ba4d5644179fb57cf825a5 Mon Sep 17 00:00:00 2001 From: NoDRM Date: Sun, 6 Aug 2023 15:49:52 +0200 Subject: [PATCH] Fix more Py2/Py3 stuff --- DeDRM_plugin/__calibre_compat_code.py | 5 +++-- DeDRM_plugin/__main__.py | 13 ++++++++++++- DeDRM_plugin/convert2xml.py | 5 ++++- DeDRM_plugin/epubtest.py | 2 ++ DeDRM_plugin/genbook.py | 4 +++- DeDRM_plugin/ignoblekeyGenPassHash.py | 2 ++ DeDRM_plugin/ignoblekeyNookStudy.py | 2 ++ DeDRM_plugin/ineptepub.py | 2 ++ DeDRM_plugin/ineptpdf.py | 3 ++- DeDRM_plugin/ion.py | 5 ++++- DeDRM_plugin/kindlekey.py | 2 ++ DeDRM_plugin/kindlepid.py | 3 ++- 12 files changed, 40 insertions(+), 8 deletions(-) diff --git a/DeDRM_plugin/__calibre_compat_code.py b/DeDRM_plugin/__calibre_compat_code.py index 85eae0c..b44b8f3 100644 --- a/DeDRM_plugin/__calibre_compat_code.py +++ b/DeDRM_plugin/__calibre_compat_code.py @@ -14,7 +14,8 @@ if "calibre" in sys.modules and sys.version_info[0] == 2: if os.path.join(config_dir, "plugins", "DeDRM.zip") not in sys.path: sys.path.insert(0, os.path.join(config_dir, "plugins", "DeDRM.zip")) -# Explicitly set the package identifier so we are allowed to import stuff ... -__package__ = "calibre_plugins.dedrm" +if "calibre" in sys.modules: + # Explicitly set the package identifier so we are allowed to import stuff ... + __package__ = "calibre_plugins.dedrm" #@@CALIBRE_COMPAT_CODE_END@@ diff --git a/DeDRM_plugin/__main__.py b/DeDRM_plugin/__main__.py index 96b4217..6c925d2 100644 --- a/DeDRM_plugin/__main__.py +++ b/DeDRM_plugin/__main__.py @@ -5,10 +5,21 @@ # (CLI interface without Calibre) # Copyright © 2021 NoDRM +""" + +NOTE: This code is not functional (yet). I started working on it a while ago +to make a standalone version of the plugins that could work without Calibre, +too, but for now there's only a rough code structure and no working code yet. + +Currently, to use these plugins, you will need to use Calibre. Hopwfully that'll +change in the future. + +""" + __license__ = 'GPL v3' __docformat__ = 'restructuredtext en' -# For revision history see __init__.py +# For revision history see CHANGELOG.md """ Run DeDRM plugin without Calibre. diff --git a/DeDRM_plugin/convert2xml.py b/DeDRM_plugin/convert2xml.py index 6af190b..1a70844 100644 --- a/DeDRM_plugin/convert2xml.py +++ b/DeDRM_plugin/convert2xml.py @@ -5,7 +5,10 @@ # For use with Topaz Scripts Version 2.6 # Python 3, September 2020 -from utilities import SafeUnbuffered + +#@@CALIBRE_COMPAT_CODE@@ + +from .utilities import SafeUnbuffered import sys import csv diff --git a/DeDRM_plugin/epubtest.py b/DeDRM_plugin/epubtest.py index 8b7fa04..da0ee95 100644 --- a/DeDRM_plugin/epubtest.py +++ b/DeDRM_plugin/epubtest.py @@ -49,6 +49,8 @@ __version__ = '2.0' +#@@CALIBRE_COMPAT_CODE@@ + import sys, struct, os, traceback import zlib import zipfile diff --git a/DeDRM_plugin/genbook.py b/DeDRM_plugin/genbook.py index b0624fd..0d49f10 100644 --- a/DeDRM_plugin/genbook.py +++ b/DeDRM_plugin/genbook.py @@ -4,7 +4,9 @@ # Python 3 for calibre 5.0 from __future__ import print_function -from utilities import SafeUnbuffered +#@@CALIBRE_COMPAT_CODE@@ + +from .utilities import SafeUnbuffered import sys import csv diff --git a/DeDRM_plugin/ignoblekeyGenPassHash.py b/DeDRM_plugin/ignoblekeyGenPassHash.py index 65d1733..f050bd9 100644 --- a/DeDRM_plugin/ignoblekeyGenPassHash.py +++ b/DeDRM_plugin/ignoblekeyGenPassHash.py @@ -45,6 +45,8 @@ import os import hashlib import base64 +#@@CALIBRE_COMPAT_CODE@@ + try: from Cryptodome.Cipher import AES except ImportError: diff --git a/DeDRM_plugin/ignoblekeyNookStudy.py b/DeDRM_plugin/ignoblekeyNookStudy.py index 99db9b5..7916c39 100644 --- a/DeDRM_plugin/ignoblekeyNookStudy.py +++ b/DeDRM_plugin/ignoblekeyNookStudy.py @@ -27,6 +27,8 @@ import hashlib import getopt import re +#@@CALIBRE_COMPAT_CODE@@ + from .utilities import SafeUnbuffered try: diff --git a/DeDRM_plugin/ineptepub.py b/DeDRM_plugin/ineptepub.py index b655ffd..3802f71 100644 --- a/DeDRM_plugin/ineptepub.py +++ b/DeDRM_plugin/ineptepub.py @@ -70,6 +70,8 @@ def unpad(data, padding=16): return data[:-pad_len] +#@@CALIBRE_COMPAT_CODE@@ + from .utilities import SafeUnbuffered from .argv_utils import unicode_argv diff --git a/DeDRM_plugin/ineptpdf.py b/DeDRM_plugin/ineptpdf.py index 69a9ca5..6d53b95 100755 --- a/DeDRM_plugin/ineptpdf.py +++ b/DeDRM_plugin/ineptpdf.py @@ -92,13 +92,14 @@ def unpad(data, padding=16): return data[:-pad_len] +#@@CALIBRE_COMPAT_CODE@@ from .utilities import SafeUnbuffered +from .argv_utils import unicode_argv iswindows = sys.platform.startswith('win') isosx = sys.platform.startswith('darwin') -from .argv_utils import unicode_argv class ADEPTError(Exception): pass diff --git a/DeDRM_plugin/ion.py b/DeDRM_plugin/ion.py index 63084e0..7dd39a5 100644 --- a/DeDRM_plugin/ion.py +++ b/DeDRM_plugin/ion.py @@ -30,6 +30,9 @@ import struct from io import BytesIO +#@@CALIBRE_COMPAT_CODE@@ + + try: from Cryptodome.Cipher import AES from Cryptodome.Util.py3compat import bchr @@ -57,7 +60,7 @@ except ImportError: # Windows-friendly choice: pylzma wheels import pylzma as lzma -from kfxtables import * +from .kfxtables import * TID_NULL = 0 TID_BOOLEAN = 1 diff --git a/DeDRM_plugin/kindlekey.py b/DeDRM_plugin/kindlekey.py index 9206d83..9dc5381 100644 --- a/DeDRM_plugin/kindlekey.py +++ b/DeDRM_plugin/kindlekey.py @@ -62,6 +62,8 @@ except NameError: # Routines common to Mac and PC +#@@CALIBRE_COMPAT_CODE@@ + from .utilities import SafeUnbuffered from .argv_utils import unicode_argv diff --git a/DeDRM_plugin/kindlepid.py b/DeDRM_plugin/kindlepid.py index 2d53b99..a851ee5 100644 --- a/DeDRM_plugin/kindlepid.py +++ b/DeDRM_plugin/kindlepid.py @@ -16,8 +16,9 @@ import sys import binascii -from .utilities import SafeUnbuffered +#@@CALIBRE_COMPAT_CODE@@ +from .utilities import SafeUnbuffered from .argv_utils import unicode_argv letters = b'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789'