1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 09:46:25 +00:00

fix files with ' or " by using arg lists instead of strings (#581)

* replace popen with subprocess run

* add splitlines

* remove stdin

* fix xml

* fix error logging and 7zip
This commit is contained in:
Alex Xu
2023-11-09 14:27:09 -08:00
committed by GitHub
parent 65062f8984
commit 431862a2e9
3 changed files with 37 additions and 50 deletions

View File

@@ -29,7 +29,7 @@ from subprocess import STDOUT, PIPE
# noinspection PyUnresolvedReferences
from PyQt5 import QtGui, QtCore, QtWidgets, QtNetwork
from xml.sax.saxutils import escape
from psutil import Popen, Process
from psutil import Process
from copy import copy
from distutils.version import StrictVersion
from raven import Client
@@ -839,24 +839,22 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
os.chmod('/usr/local/bin/kindlegen', 0o755)
except Exception:
pass
kindleGenExitCode = Popen('kindlegen -locale en', stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True)
kindleGenExitCode.communicate()
kindleGenExitCode = subprocess.run(['kindlegen', '-locale', 'en'], stdout=PIPE, stderr=STDOUT, encoding='UTF-8')
if kindleGenExitCode.returncode == 0:
self.kindleGen = True
versionCheck = Popen('kindlegen -locale en', stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True)
for line in versionCheck.stdout:
line = line.decode("utf-8")
versionCheck = subprocess.run(['kindlegen', '-locale', 'en'], stdout=PIPE, stderr=STDOUT, encoding='UTF-8')
for line in versionCheck.stdout.splitlines():
if 'Amazon kindlegen' in line:
versionCheck = line.split('V')[1].split(' ')[0]
if StrictVersion(versionCheck) < StrictVersion('2.9'):
self.addMessage('Your <a href="https://www.amazon.com/b?node=23496309011">KindleGen</a>'
' is outdated! MOBI conversion might fail.', 'warning')
break
where_command = 'where kindlegen.exe'
where_command = ['where', 'kindlegen.exe']
if os.name == 'posix':
where_command = 'which kindlegen'
process = subprocess.run(where_command, stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True)
locations = process.stdout.decode('utf-8').split('\n')
where_command = ['which', 'kindlegen']
process = subprocess.run(where_command, stdout=PIPE, stderr=STDOUT, encoding='UTF-8')
locations = process.stdout.splitlines()
self.addMessage(f"<b>KindleGen Found:</b> {locations[0]}", 'info')
else:
self.kindleGen = False
@@ -1039,8 +1037,7 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
self.addMessage('Since you are a new user of <b>KCC</b> please see few '
'<a href="https://github.com/ciromattia/kcc/wiki/Important-tips">important tips</a>.',
'info')
process = Popen('7z', stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True)
process.communicate()
process = subprocess.run(['7z'], stdout=PIPE, stderr=STDOUT)
if process.returncode == 0 or process.returncode == 7:
self.sevenzip = True
else: