Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide 7z/kindlegen consoles on Windows #656

Merged
merged 5 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions kindlecomicconverter/KCC_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from . import kindle
from . import KCC_ui
from . import KCC_ui_editor
from .utils import run_subprocess_silent


class QApplicationMessaging(QtWidgets.QApplication):
Expand Down Expand Up @@ -837,7 +838,7 @@ def detectKindleGen(self, startup=False):
except Exception:
pass
try:
versionCheck = subprocess.run(['kindlegen', '-locale', 'en'], stdout=PIPE, stderr=STDOUT, encoding='UTF-8')
versionCheck = run_subprocess_silent(['kindlegen', '-locale', 'en'], stdout=PIPE, stderr=STDOUT, encoding='UTF-8')
self.kindleGen = True
for line in versionCheck.stdout.splitlines():
if 'Amazon kindlegen' in line:
Expand Down Expand Up @@ -1026,7 +1027,7 @@ def __init__(self, kccapp, kccwindow):
'<a href="https://github.com/ciromattia/kcc/wiki/Important-tips">important tips</a>.',
'info')
try:
subprocess.run(['7z'], stdout=PIPE, stderr=STDOUT)
run_subprocess_silent(['7z'], stdout=PIPE, stderr=STDOUT)
self.sevenzip = True
except FileNotFoundError:
self.sevenzip = False
Expand Down
7 changes: 4 additions & 3 deletions kindlecomicconverter/comic2ebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from . import metadata
from . import kindle
from . import __version__
from .utils import run_subprocess_silent


def main(argv=None):
Expand Down Expand Up @@ -1104,13 +1105,13 @@ def checkTools(source):
if source.endswith('.CB7') or source.endswith('.7Z') or source.endswith('.RAR') or source.endswith('.CBR') or \
source.endswith('.ZIP') or source.endswith('.CBZ'):
try:
subprocess.run(['7z'], stdout=PIPE, stderr=STDOUT)
run_subprocess_silent(['7z'], stdout=PIPE, stderr=STDOUT)
except FileNotFoundError:
print('ERROR: 7z is missing!')
sys.exit(1)
if options.format == 'MOBI':
try:
subprocess.run(['kindlegen', '-locale', 'en'], stdout=PIPE, stderr=STDOUT)
run_subprocess_silent(['kindlegen', '-locale', 'en'], stdout=PIPE, stderr=STDOUT)
except FileNotFoundError:
print('ERROR: KindleGen is missing!')
sys.exit(1)
Expand Down Expand Up @@ -1267,7 +1268,7 @@ def makeMOBIWorker(item):
kindlegenError = ''
try:
if os.path.getsize(item) < 629145600:
output = subprocess.run(['kindlegen', '-dont_append_source', '-locale', 'en', item],
output = run_subprocess_silent(['kindlegen', '-dont_append_source', '-locale', 'en', item],
stdout=PIPE, stderr=STDOUT, encoding='UTF-8')
for line in output.stdout.splitlines():
# ERROR: Generic error
Expand Down
15 changes: 8 additions & 7 deletions kindlecomicconverter/comicarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from subprocess import STDOUT, PIPE
from xml.dom.minidom import parseString
from xml.parsers.expat import ExpatError
from .utils import run_subprocess_silent

EXTRACTION_ERROR = 'Failed to extract archive. Try extracting file outside of KCC.'

Expand All @@ -36,13 +37,13 @@ def __init__(self, filepath):
self.type = None
if not os.path.isfile(self.filepath):
raise OSError('File not found.')
process = subprocess.run(['7z', 'l', '-y', '-p1', self.filepath], stderr=STDOUT, stdout=PIPE)
process = run_subprocess_silent(['7z', 'l', '-y', '-p1', self.filepath], stderr=STDOUT, stdout=PIPE)
for line in process.stdout.splitlines():
if b'Type =' in line:
self.type = line.rstrip().decode().split(' = ')[1].upper()
break
if process.returncode != 0 and distro.id() == 'fedora':
process = subprocess.run(['unrar', 'l', '-y', '-p1', self.filepath], stderr=STDOUT, stdout=PIPE)
process = run_subprocess_silent(['unrar', 'l', '-y', '-p1', self.filepath], stderr=STDOUT, stdout=PIPE)
for line in process.stdout.splitlines():
if b'Details: ' in line:
self.type = line.rstrip().decode().split(' ')[1].upper()
Expand All @@ -53,15 +54,15 @@ def __init__(self, filepath):
def extract(self, targetdir):
if not os.path.isdir(targetdir):
raise OSError('Target directory doesn\'t exist.')
process = subprocess.run(['7z', 'x', '-y', '-xr!__MACOSX', '-xr!.DS_Store', '-xr!thumbs.db', '-xr!Thumbs.db', '-o' + targetdir, self.filepath],
process = run_subprocess_silent(['7z', 'x', '-y', '-xr!__MACOSX', '-xr!.DS_Store', '-xr!thumbs.db', '-xr!Thumbs.db', '-o' + targetdir, self.filepath],
stdout=PIPE, stderr=STDOUT)
if process.returncode != 0 and distro.id() == 'fedora':
process = subprocess.run(['unrar', 'x', '-y', '-x__MACOSX', '-x.DS_Store', '-xthumbs.db', '-xThumbs.db', self.filepath, targetdir]
process = run_subprocess_silent(['unrar', 'x', '-y', '-x__MACOSX', '-x.DS_Store', '-xthumbs.db', '-xThumbs.db', self.filepath, targetdir]
, stdout=PIPE, stderr=STDOUT)
if process.returncode != 0:
raise OSError(EXTRACTION_ERROR)
elif process.returncode != 0 and platform.system() == 'Darwin':
process = subprocess.run(['unar', self.filepath, '-f', '-o', targetdir],
process = run_subprocess_silent(['unar', self.filepath, '-f', '-o', targetdir],
stdout=PIPE, stderr=STDOUT)
elif process.returncode != 0:
raise OSError(EXTRACTION_ERROR)
Expand All @@ -73,13 +74,13 @@ def extract(self, targetdir):
def addFile(self, sourcefile):
if self.type in ['RAR', 'RAR5']:
raise NotImplementedError
process = subprocess.run(['7z', 'a', '-y', self.filepath, sourcefile],
process = run_subprocess_silent(['7z', 'a', '-y', self.filepath, sourcefile],
stdout=PIPE, stderr=STDOUT)
if process.returncode != 0:
raise OSError('Failed to add the file.')

def extractMetadata(self):
process = subprocess.run(['7z', 'x', '-y', '-so', self.filepath, 'ComicInfo.xml'],
process = run_subprocess_silent(['7z', 'x', '-y', '-so', self.filepath, 'ComicInfo.xml'],
stdout=PIPE, stderr=STDOUT)
if process.returncode != 0:
raise OSError(EXTRACTION_ERROR)
Expand Down
10 changes: 10 additions & 0 deletions kindlecomicconverter/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os
import subprocess

def run_subprocess_silent(command, **kwargs):
VampiroMedicado marked this conversation as resolved.
Show resolved Hide resolved
if (os.name == 'nt'):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
kwargs.setdefault('startupinfo', startupinfo)
VampiroMedicado marked this conversation as resolved.
Show resolved Hide resolved
return subprocess.run(command, **kwargs)