From 72fff2a297f5bc555db4a1559f44c6b21d6d65f6 Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Wed, 22 Aug 2018 21:24:28 +0200 Subject: [PATCH] Update for running calibre-convert in docker --- cps/worker.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/cps/worker.py b/cps/worker.py index 58b178d0..3575fe17 100644 --- a/cps/worker.py +++ b/cps/worker.py @@ -233,15 +233,23 @@ class WorkerThread(threading.Thread): if web.ub.config.config_ebookconverter == 1: command = [web.ub.config.config_converterpath, u'"' + file_path + u'.epub"'] else: - command = [web.ub.config.config_converterpath, '"' + file_path + u'.epub"', - '"'+file_path + u'.mobi"'] - if web.ub.config.config_calibre: - command.append(web.ub.config.config_calibre) - # special handling for windows - if os.name == 'nt': - command = ' '.join(command) - if sys.version_info < (3, 0): - command = command.encode(sys.getfilesystemencoding()) + # Linux py2.7 encode as list without quotes no empty element for parameters + # linux py3.x no encode and as list without quotes no empty element for parameters + # windows py2.7 encode as string with qoutes empty element for parameters is okay + # windows py 3.x no encode and as string with qoutes empty element for parameters is okay + # seperate handling for windows and linux + if os.name == 'nt': + command = web.ub.config.config_converterpath + u' "' + file_path + u'.epub" "' + \ + file_path + u'.mobi" ' + web.ub.config.config_calibre + if sys.version_info < (3, 0): + command = command.encode(sys.getfilesystemencoding()) + else: + command = [web.ub.config.config_converterpath, (file_path + u'.epub'), + (file_path + u'.mobi')] + if web.ub.config.config_calibre: + command.append(web.ub.config.config_calibre) + if sys.version_info < (3, 0): + command = [ x.encode(sys.getfilesystemencoding()) for x in command ] p = subprocess.Popen(command, stdout=subprocess.PIPE, universal_newlines=True) except OSError as e: