mirror of
https://github.com/ciromattia/kcc
synced 2026-07-11 15:33:17 +00:00
more detailed kindlegen warnings (#1390)
* show kindlegen warnings and errors * show kindlegen warnings * dump kindlegen logs to txt * move warnings to end * don't show webtoon cover warning * fix typo * add timestamp to kindlegen log dump * double enter * add TODO * add more TODO * fix comment * final clean up
This commit is contained in:
@@ -558,8 +558,6 @@ class WorkerThread(QThread):
|
|||||||
MW.addMessage.emit('Created EPUB file was too big. Weird file structure?', 'error', False)
|
MW.addMessage.emit('Created EPUB file was too big. Weird file structure?', 'error', False)
|
||||||
MW.addMessage.emit('EPUB file: ' + str(epubSize) + 'MB. Supported size: ~350MB.', 'error',
|
MW.addMessage.emit('EPUB file: ' + str(epubSize) + 'MB. Supported size: ~350MB.', 'error',
|
||||||
False)
|
False)
|
||||||
if self.kindlegenErrorCode[0] == 3221226505:
|
|
||||||
MW.addMessage.emit('Unknown Windows error. Possibly filepath too long?', 'error', False)
|
|
||||||
else:
|
else:
|
||||||
for item in outputPath:
|
for item in outputPath:
|
||||||
if GUI.targetDirectory and GUI.targetDirectory != os.path.dirname(item):
|
if GUI.targetDirectory and GUI.targetDirectory != os.path.dirname(item):
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
@@ -1992,8 +1993,14 @@ def makeMOBIWorkerTick(output):
|
|||||||
makeMOBIWorkerOutput.append(output)
|
makeMOBIWorkerOutput.append(output)
|
||||||
if output[0] != 0:
|
if output[0] != 0:
|
||||||
makeMOBIWorkerPool.terminate()
|
makeMOBIWorkerPool.terminate()
|
||||||
|
for warning in output[3]:
|
||||||
|
print(warning)
|
||||||
if GUI:
|
if GUI:
|
||||||
GUI.progressBarTick.emit('tick')
|
GUI.progressBarTick.emit('tick')
|
||||||
|
if output[3]:
|
||||||
|
for warning in output[3]:
|
||||||
|
GUI.addMessage.emit(warning, 'warning', False)
|
||||||
|
GUI.addMessage.emit('', '', False)
|
||||||
if not GUI.conversionAlive:
|
if not GUI.conversionAlive:
|
||||||
makeMOBIWorkerPool.terminate()
|
makeMOBIWorkerPool.terminate()
|
||||||
|
|
||||||
@@ -2003,8 +2010,10 @@ def makeMOBIWorker(item):
|
|||||||
kindlegenErrorCode = 0
|
kindlegenErrorCode = 0
|
||||||
kindlegenError = ''
|
kindlegenError = ''
|
||||||
try:
|
try:
|
||||||
|
# TODO: This size check is incorrect, I think kindlegen increased the limit
|
||||||
if os.path.getsize(item) < 629145600:
|
if os.path.getsize(item) < 629145600:
|
||||||
start = perf_counter()
|
start = perf_counter()
|
||||||
|
# TODO: should anything be done with the kindlegen output during successes?
|
||||||
output = subprocess_run(['kindlegen', '-dont_append_source', '-locale', 'en', item],
|
output = subprocess_run(['kindlegen', '-dont_append_source', '-locale', 'en', item],
|
||||||
stdout=PIPE, stderr=STDOUT, encoding='UTF-8', errors='ignore', check=True)
|
stdout=PIPE, stderr=STDOUT, encoding='UTF-8', errors='ignore', check=True)
|
||||||
end = perf_counter()
|
end = perf_counter()
|
||||||
@@ -2012,27 +2021,47 @@ def makeMOBIWorker(item):
|
|||||||
else:
|
else:
|
||||||
# ERROR: EPUB too big
|
# ERROR: EPUB too big
|
||||||
kindlegenErrorCode = 23026
|
kindlegenErrorCode = 23026
|
||||||
return [kindlegenErrorCode, kindlegenError, item]
|
return [kindlegenErrorCode, kindlegenError, item, []]
|
||||||
except CalledProcessError as err:
|
except CalledProcessError as err:
|
||||||
|
warnings = []
|
||||||
for line in err.stdout.splitlines():
|
for line in err.stdout.splitlines():
|
||||||
# ERROR: Generic error
|
# ERROR: Generic error
|
||||||
if "Error(" in line:
|
if "Error(" in line:
|
||||||
kindlegenErrorCode = 1
|
kindlegenErrorCode = 1
|
||||||
kindlegenError = err.stdout
|
kindlegenError = '\n\n'.join(warnings + [line, 'kindlegen logs dumped'])
|
||||||
|
try:
|
||||||
|
timestamp = datetime.now().isoformat(timespec='seconds').replace(':', '_')
|
||||||
|
with open(os.path.join(os.path.dirname(item), f'kindlegen_log_{timestamp}.txt'), 'w') as f:
|
||||||
|
f.write(err.stdout)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
# examples
|
||||||
|
# Warning(prcgen):W14019: Cover is too small
|
||||||
|
if "Warning(" in line:
|
||||||
|
if ":W14016: Cover not specified" in line and options.webtoon:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
warnings.append(line)
|
||||||
# ERROR: EPUB too big
|
# ERROR: EPUB too big
|
||||||
if ":E23026:" in line:
|
if ":E23026:" in line:
|
||||||
kindlegenErrorCode = 23026
|
kindlegenErrorCode = 23026
|
||||||
|
if ":E23028:" in line:
|
||||||
|
kindlegenErrorCode = 23028
|
||||||
if kindlegenErrorCode > 0:
|
if kindlegenErrorCode > 0:
|
||||||
break
|
break
|
||||||
if ":I1036: Mobi file built successfully" in line:
|
if ":I1036: Mobi file built successfully" in line:
|
||||||
return [0, '', item]
|
return [0, '', item, warnings]
|
||||||
if ":I1037: Mobi file built with WARNINGS!" in line:
|
if ":I1037: Mobi file built with WARNINGS!" in line:
|
||||||
return [0, '', item]
|
return [0, '', item, warnings]
|
||||||
# ERROR: KCC unknown generic error
|
# ERROR: KCC unknown generic error
|
||||||
if kindlegenErrorCode == 0:
|
if kindlegenErrorCode == 0:
|
||||||
kindlegenErrorCode = err.returncode
|
kindlegenErrorCode = -1
|
||||||
kindlegenError = err.stdout
|
if err.returncode == 3221226505:
|
||||||
return [kindlegenErrorCode, kindlegenError, item]
|
kindlegenError = f'Error {err.returncode}: Unknown Windows error. Possibly filepath too long?'
|
||||||
|
else:
|
||||||
|
kindlegenError = f'Error {err.returncode}'
|
||||||
|
return [kindlegenErrorCode, kindlegenError, item, warnings]
|
||||||
|
|
||||||
|
|
||||||
def makeMOBI(work, qtgui=None):
|
def makeMOBI(work, qtgui=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user