2
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-13 19:10:30 +00:00

Merge branch 'embed_metadata_on_convert' into embed_metadata_on_download

This commit is contained in:
Thore Schillmann 2022-07-07 14:09:15 +00:00
commit c89bc12c9b
5 changed files with 20 additions and 19 deletions

View File

@ -43,7 +43,7 @@ from . import constants, logger, helper, services, cli_param
from . import db, calibre_db, ub, web_server, config, updater_thread, gdriveutils, \ from . import db, calibre_db, ub, web_server, config, updater_thread, gdriveutils, \
kobo_sync_status, schedule kobo_sync_status, schedule
from .helper import check_valid_domain, send_test_mail, reset_password, generate_password_hash, check_email, \ from .helper import check_valid_domain, send_test_mail, reset_password, generate_password_hash, check_email, \
valid_email, check_username valid_email, check_username, get_calibre_binarypath
from .gdriveutils import is_gdrive_ready, gdrive_support from .gdriveutils import is_gdrive_ready, gdrive_support
from .render_template import render_title_template, get_sidebar_config from .render_template import render_title_template, get_sidebar_config
from .services.worker import WorkerThread from .services.worker import WorkerThread
@ -1727,8 +1727,7 @@ def _configuration_update_helper():
calibre_status = helper.check_calibre(config.config_binariesdir) calibre_status = helper.check_calibre(config.config_binariesdir)
if calibre_status: if calibre_status:
return _configuration_result(calibre_status) return _configuration_result(calibre_status)
# ToDo: Remove this and 'self.config_converterpath' and replace with 'config.get_calibre_binarypath("ebook-convert")' everywhere to_save["config_converterpath"] = get_calibre_binarypath("ebook-convert")
to_save["config_converterpath"] = config.get_calibre_binarypath("ebook-convert")
_config_string(to_save, "config_converterpath") _config_string(to_save, "config_converterpath")
reboot_required |= _config_int(to_save, "config_login_type") reboot_required |= _config_int(to_save, "config_login_type")

View File

@ -269,15 +269,6 @@ class _ConfigSQL(object):
def get_scheduled_task_settings(self): def get_scheduled_task_settings(self):
return {k:v for k, v in self.__dict__.items() if k.startswith('schedule_')} return {k:v for k, v in self.__dict__.items() if k.startswith('schedule_')}
def get_calibre_binarypath(self, binary):
binariesdir = self.config_binariesdir
if binariesdir:
if binary in constants.SUPPORTED_CALIBRE_BINARIES:
return os.path.join(binariesdir, binary)
else:
raise ValueError("'{}' is not a supported Calibre binary".format(binary))
return ""
def set_from_dictionary(self, dictionary, field, convertor=None, default=None, encode=None): def set_from_dictionary(self, dictionary, field, convertor=None, default=None, encode=None):
"""Possibly updates a field of this object. """Possibly updates a field of this object.
The new value, if present, is grabbed from the given dictionary, and optionally passed through a convertor. The new value, if present, is grabbed from the given dictionary, and optionally passed through a convertor.
@ -428,7 +419,7 @@ def autodetect_calibre_binaries():
else: else:
calibre_path = ["/opt/calibre/"] calibre_path = ["/opt/calibre/"]
for element in calibre_path: for element in calibre_path:
supported_binary_paths = [os.path.join(element, binary) for binary in constants.SUPPORTED_CALIBRE_BINARIES] supported_binary_paths = [os.path.join(element, binary) for binary in constants.SUPPORTED_CALIBRE_BINARIES.values()]
if all(os.path.isfile(binary_path) and os.access(binary_path, os.X_OK) for binary_path in supported_binary_paths): if all(os.path.isfile(binary_path) and os.access(binary_path, os.X_OK) for binary_path in supported_binary_paths):
values = [process_wait([binary_path, "--version"], pattern='\(calibre (.*)\)') for binary_path in supported_binary_paths] values = [process_wait([binary_path, "--version"], pattern='\(calibre (.*)\)') for binary_path in supported_binary_paths]
if all(values): if all(values):

View File

@ -154,7 +154,7 @@ EXTENSIONS_UPLOAD = {'txt', 'pdf', 'epub', 'kepub', 'mobi', 'azw', 'azw3', 'cbr'
_extension = "" _extension = ""
if sys.platform == "win32": if sys.platform == "win32":
_extension = ".exe" _extension = ".exe"
SUPPORTED_CALIBRE_BINARIES = [binary + _extension for binary in ["ebook-convert", "calibredb"]] SUPPORTED_CALIBRE_BINARIES = {binary:binary + _extension for binary in ["ebook-convert", "calibredb"]}
def has_flag(value, bit_flag): def has_flag(value, bit_flag):

View File

@ -972,7 +972,7 @@ def check_calibre(calibre_location):
return _('Please specify a directory, not a file') return _('Please specify a directory, not a file')
try: try:
supported_binary_paths = [os.path.join(calibre_location, binary) for binary in SUPPORTED_CALIBRE_BINARIES] supported_binary_paths = [os.path.join(calibre_location, binary) for binary in SUPPORTED_CALIBRE_BINARIES.values()]
binaries_available=[os.path.isfile(binary_path) and os.access(binary_path, os.X_OK) for binary_path in supported_binary_paths] binaries_available=[os.path.isfile(binary_path) and os.access(binary_path, os.X_OK) for binary_path in supported_binary_paths]
if all(binaries_available): if all(binaries_available):
values = [process_wait([binary_path, "--version"], pattern='\(calibre (.*)\)') for binary_path in supported_binary_paths] values = [process_wait([binary_path, "--version"], pattern='\(calibre (.*)\)') for binary_path in supported_binary_paths]
@ -982,7 +982,7 @@ def check_calibre(calibre_location):
else: else:
return _('Calibre binaries not viable') return _('Calibre binaries not viable')
else: else:
missing_binaries=[path for path, available in zip(SUPPORTED_CALIBRE_BINARIES, binaries_available) if not available] missing_binaries=[path for path, available in zip(SUPPORTED_CALIBRE_BINARIES.values(), binaries_available) if not available]
return _('Missing calibre binaries: %(missing)s', missing=", ".join(missing_binaries)) return _('Missing calibre binaries: %(missing)s', missing=", ".join(missing_binaries))
except (OSError, UnicodeDecodeError) as err: except (OSError, UnicodeDecodeError) as err:
@ -1053,6 +1053,17 @@ def get_download_link(book_id, book_format, client):
abort(404) abort(404)
def get_calibre_binarypath(binary):
binariesdir = config.config_binariesdir
if binariesdir:
try:
return os.path.join(binariesdir, SUPPORTED_CALIBRE_BINARIES[binary])
except KeyError as ex:
log.error("Binary not supported by Calibre-Web: %s", SUPPORTED_CALIBRE_BINARIES[binary])
pass
return ""
def clear_cover_thumbnail_cache(book_id): def clear_cover_thumbnail_cache(book_id):
if config.schedule_generate_book_covers: if config.schedule_generate_book_covers:
WorkerThread.add(None, TaskClearCoverThumbnailCache(book_id), hidden=True) WorkerThread.add(None, TaskClearCoverThumbnailCache(book_id), hidden=True)

View File

@ -37,7 +37,7 @@ from cps.ub import init_db_thread
from cps.tasks.mail import TaskEmail from cps.tasks.mail import TaskEmail
from cps import gdriveutils from cps import gdriveutils
from cps.constants import SUPPORTED_CALIBRE_BINARIES
log = logger.create() log = logger.create()
@ -238,7 +238,7 @@ class TaskConvert(CalibreTask):
tmp_dir = os.path.join(gettempdir(), 'calibre_web') tmp_dir = os.path.join(gettempdir(), 'calibre_web')
if not os.path.isdir(tmp_dir): if not os.path.isdir(tmp_dir):
os.mkdir(tmp_dir) os.mkdir(tmp_dir)
calibredb_binarypath = config.get_calibre_binarypath("calibredb") calibredb_binarypath = os.path.join(config.config_binariesdir, SUPPORTED_CALIBRE_BINARIES["calibredb"])
opf_command = [calibredb_binarypath, 'show_metadata', '--as-opf', str(book_id), '--with-library', config.config_calibre_dir] opf_command = [calibredb_binarypath, 'show_metadata', '--as-opf', str(book_id), '--with-library', config.config_calibre_dir]
p = process_open(opf_command, quotes) p = process_open(opf_command, quotes)
p.wait() p.wait()
@ -259,7 +259,7 @@ class TaskConvert(CalibreTask):
quotes_index += 1 quotes_index += 1
p = process_open(command, quotes, newlines=False) p = process_open(command, quotes, newlines=False)
except (ValueError, OSError) as e: except OSError as e:
return 1, N_(u"Ebook-converter failed: %(error)s", error=e) return 1, N_(u"Ebook-converter failed: %(error)s", error=e)
while p.poll() is None: while p.poll() is None: