From e4eab175958cbd923a6f516a4fbadb2744c87d7c Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 24 May 2020 17:24:54 +0200 Subject: [PATCH] Fix version detect of binaries on windows --- cps/config_sql.py | 6 ++++-- cps/helper.py | 5 +++-- cps/subproc_wrapper.py | 7 ++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cps/config_sql.py b/cps/config_sql.py index c5287d36..b11d84fd 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -362,8 +362,10 @@ def _migrate_table(session, orm_class): def autodetect_calibre_binary(): if sys.platform == "win32": - calibre_path = ["C:\\program files\calibre\calibre-convert.exe", - "C:\\program files(x86)\calibre\calibre-convert.exe"] + calibre_path = ["C:\\program files\calibre\ebook-convert.exe", + "C:\\program files(x86)\calibre\ebook-convert.exe", + "C:\\program files(x86)\calibre2\ebook-convert.exe", + "C:\\program files\calibre2\ebook-convert.exe"] else: calibre_path = ["/opt/calibre/ebook-convert"] for element in calibre_path: diff --git a/cps/helper.py b/cps/helper.py index b59d9bed..a4715033 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -634,11 +634,12 @@ def check_unrar(unrarLocation): unrarLocation = unrarLocation.encode(sys.getfilesystemencoding()) unrarLocation = [unrarLocation] for lines in process_wait(unrarLocation): - value = re.search('UNRAR (.*) freeware', lines) + value = re.search('UNRAR (.*) freeware', lines, re.IGNORECASE) if value: version = value.group(1) log.debug("unrar version %s", version) - except OSError as err: + break + except (OSError, UnicodeDecodeError) as err: log.exception(err) return _('Error excecuting UnRar') diff --git a/cps/subproc_wrapper.py b/cps/subproc_wrapper.py index 0ad1c1d2..23facbd7 100644 --- a/cps/subproc_wrapper.py +++ b/cps/subproc_wrapper.py @@ -22,7 +22,7 @@ import os import subprocess -def process_open(command, quotes=(), env=None, sout=subprocess.PIPE, serr=subprocess.PIPE): +def process_open(command, quotes=(), env=None, sout=subprocess.PIPE, serr=subprocess.PIPE, newlines=True): # 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 quotes empty element for parameters is okay @@ -41,12 +41,13 @@ def process_open(command, quotes=(), env=None, sout=subprocess.PIPE, serr=subpro else: exc_command = [x for x in command] - return subprocess.Popen(exc_command, shell=False, stdout=sout, stderr=serr, universal_newlines=True, env=env) + return subprocess.Popen(exc_command, shell=False, stdout=sout, stderr=serr, universal_newlines=newlines, env=env) def process_wait(command, serr=subprocess.PIPE): # Run command, wait for process to terminate, and return an iterator over lines of its output. - p = process_open(command, serr=serr) + newlines = os.name != 'nt' + p = process_open(command, serr=serr, newlines=newlines) p.wait() for line in p.stdout.readlines(): if isinstance(line, bytes):