2018-07-18 20:21:44 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-01-20 20:37:45 +02:00
|
|
|
|
|
|
|
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
|
|
|
|
# Copyright (C) 2016-2019 Ben Bennett, OzzieIsaacs
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2019-06-06 17:10:22 +02:00
|
|
|
from __future__ import division, print_function, unicode_literals
|
2018-07-18 20:21:44 +02:00
|
|
|
import os
|
|
|
|
import re
|
2019-10-20 15:48:06 +02:00
|
|
|
from flask_babel import gettext as _
|
2019-06-06 17:10:22 +02:00
|
|
|
|
2019-07-14 19:38:07 +02:00
|
|
|
from . import config, logger
|
2019-07-07 14:53:38 +02:00
|
|
|
from .subproc_wrapper import process_wait
|
2018-07-18 20:21:44 +02:00
|
|
|
|
|
|
|
|
2019-07-14 19:38:07 +02:00
|
|
|
log = logger.create()
|
2018-07-18 20:21:44 +02:00
|
|
|
|
2019-10-20 15:48:06 +02:00
|
|
|
# _() necessary to make babel aware of string for translation
|
|
|
|
_NOT_CONFIGURED = _('not configured')
|
2019-07-14 19:38:07 +02:00
|
|
|
_NOT_INSTALLED = 'not installed'
|
|
|
|
_EXECUTION_ERROR = 'Execution permissions missing'
|
2018-07-18 20:21:44 +02:00
|
|
|
|
2019-07-14 19:38:07 +02:00
|
|
|
|
|
|
|
def _get_command_version(path, pattern, argument=None):
|
|
|
|
if os.path.exists(path):
|
|
|
|
command = [path]
|
|
|
|
if argument:
|
|
|
|
command.append(argument)
|
2018-07-18 20:21:44 +02:00
|
|
|
try:
|
2019-07-14 19:38:07 +02:00
|
|
|
for line in process_wait(command):
|
|
|
|
if re.search(pattern, line):
|
|
|
|
return line
|
|
|
|
except Exception as ex:
|
|
|
|
log.warning("%s: %s", path, ex)
|
|
|
|
return _EXECUTION_ERROR
|
|
|
|
return _NOT_INSTALLED
|
2018-07-18 20:21:44 +02:00
|
|
|
|
|
|
|
|
2019-07-14 19:38:07 +02:00
|
|
|
def get_version():
|
|
|
|
version = None
|
2019-02-08 21:11:44 +02:00
|
|
|
if config.config_ebookconverter == 1:
|
2019-07-14 19:38:07 +02:00
|
|
|
version = _get_command_version(config.config_converterpath, r'Amazon kindlegen\(')
|
2019-02-08 21:11:44 +02:00
|
|
|
elif config.config_ebookconverter == 2:
|
2019-07-14 19:38:07 +02:00
|
|
|
version = _get_command_version(config.config_converterpath, r'ebook-convert.*\(calibre', '--version')
|
|
|
|
return version or _NOT_CONFIGURED
|