mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-25 09:30:31 +00:00
moved get_calibre_binarypath()
to helper.py
This commit is contained in:
parent
0d34f41a48
commit
fc004f4f0c
@ -43,7 +43,7 @@ from . import constants, logger, helper, services, cli_param
|
||||
from . import db, calibre_db, ub, web_server, config, updater_thread, gdriveutils, \
|
||||
kobo_sync_status, schedule
|
||||
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 .render_template import render_title_template, get_sidebar_config
|
||||
from .services.worker import WorkerThread
|
||||
@ -1727,8 +1727,7 @@ def _configuration_update_helper():
|
||||
calibre_status = helper.check_calibre(config.config_binariesdir)
|
||||
if 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"] = config.get_calibre_binarypath("ebook-convert")
|
||||
to_save["config_converterpath"] = get_calibre_binarypath("ebook-convert")
|
||||
_config_string(to_save, "config_converterpath")
|
||||
|
||||
reboot_required |= _config_int(to_save, "config_login_type")
|
||||
|
@ -269,15 +269,6 @@ class _ConfigSQL(object):
|
||||
def get_scheduled_task_settings(self):
|
||||
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):
|
||||
"""Possibly updates a field of this object.
|
||||
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:
|
||||
calibre_path = ["/opt/calibre/"]
|
||||
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):
|
||||
values = [process_wait([binary_path, "--version"], pattern='\(calibre (.*)\)') for binary_path in supported_binary_paths]
|
||||
if all(values):
|
||||
|
@ -154,7 +154,7 @@ EXTENSIONS_UPLOAD = {'txt', 'pdf', 'epub', 'kepub', 'mobi', 'azw', 'azw3', 'cbr'
|
||||
_extension = ""
|
||||
if sys.platform == "win32":
|
||||
_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):
|
||||
|
@ -951,7 +951,7 @@ def check_calibre(calibre_location):
|
||||
return _('Please specify a directory, not a file')
|
||||
|
||||
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]
|
||||
if all(binaries_available):
|
||||
values = [process_wait([binary_path, "--version"], pattern='\(calibre (.*)\)') for binary_path in supported_binary_paths]
|
||||
@ -961,7 +961,7 @@ def check_calibre(calibre_location):
|
||||
else:
|
||||
return _('Calibre binaries not viable')
|
||||
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))
|
||||
|
||||
except (OSError, UnicodeDecodeError) as err:
|
||||
@ -1032,6 +1032,17 @@ def get_download_link(book_id, book_format, client):
|
||||
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):
|
||||
if config.schedule_generate_book_covers:
|
||||
WorkerThread.add(None, TaskClearCoverThumbnailCache(book_id), hidden=True)
|
||||
|
@ -37,7 +37,7 @@ from cps.ub import init_db_thread
|
||||
|
||||
from cps.tasks.mail import TaskEmail
|
||||
from cps import gdriveutils
|
||||
|
||||
from cps.constants import SUPPORTED_CALIBRE_BINARIES
|
||||
|
||||
log = logger.create()
|
||||
|
||||
@ -238,7 +238,7 @@ class TaskConvert(CalibreTask):
|
||||
tmp_dir = os.path.join(gettempdir(), 'calibre_web')
|
||||
if not os.path.isdir(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]
|
||||
p = process_open(opf_command, quotes)
|
||||
path_tmp_opf = os.path.join(tmp_dir, "metadata_" + str(current_milli_time()) + ".opf")
|
||||
@ -258,7 +258,7 @@ class TaskConvert(CalibreTask):
|
||||
quotes_index += 1
|
||||
|
||||
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)
|
||||
|
||||
while p.poll() is None:
|
||||
|
Loading…
Reference in New Issue
Block a user