mirror of
https://github.com/ciromattia/kcc
synced 2026-05-15 20:11:44 +00:00
Refactored KindleGen error handling
This commit is contained in:
@@ -167,44 +167,59 @@ class WorkerThread(QtCore.QThread):
|
|||||||
else:
|
else:
|
||||||
self.emit(QtCore.SIGNAL("addMessage"), 'Creating EPUB file... Done!', 'info', True)
|
self.emit(QtCore.SIGNAL("addMessage"), 'Creating EPUB file... Done!', 'info', True)
|
||||||
if str(GUI.FormatBox.currentText()) == 'MOBI':
|
if str(GUI.FormatBox.currentText()) == 'MOBI':
|
||||||
if not os.path.getsize(outputPath) > 314572800:
|
self.emit(QtCore.SIGNAL("addMessage"), 'Creating MOBI file...', 'info')
|
||||||
self.emit(QtCore.SIGNAL("addMessage"), 'Creating MOBI file...', 'info')
|
self.emit(QtCore.SIGNAL("progressBarTick"), 1)
|
||||||
self.emit(QtCore.SIGNAL("progressBarTick"), 1)
|
try:
|
||||||
try:
|
self.kindlegenErrorCode = 0
|
||||||
retcode = call('kindlegen -verbose "' + outputPath + '"', shell=True)
|
if os.path.getsize(outputPath) < 367001600:
|
||||||
except:
|
output = Popen('kindlegen "' + outputPath + '"', stdout=PIPE, stderr=STDOUT, shell=True)
|
||||||
continue
|
for line in output.stdout:
|
||||||
if retcode == 0 or retcode == 1:
|
# ERROR: Generic error
|
||||||
self.emit(QtCore.SIGNAL("addMessage"), 'Creating MOBI file... Done!', 'info', True)
|
if "Error(" in line:
|
||||||
self.emit(QtCore.SIGNAL("addMessage"), 'Removing SRCS header...', 'info')
|
self.kindlegenErrorCode = 1
|
||||||
os.remove(outputPath)
|
self.kindlegenError = line
|
||||||
mobiPath = outputPath.replace('.epub', '.mobi')
|
# ERROR: EPUB too big
|
||||||
shutil.move(mobiPath, mobiPath + '_tostrip')
|
if ":E23026:" in line:
|
||||||
try:
|
self.kindlegenErrorCode = 23026
|
||||||
kindlestrip.main((mobiPath + '_tostrip', mobiPath))
|
|
||||||
except Exception:
|
|
||||||
self.errors = True
|
|
||||||
if not self.errors:
|
|
||||||
os.remove(mobiPath + '_tostrip')
|
|
||||||
self.emit(QtCore.SIGNAL("addMessage"), 'Removing SRCS header... Done!', 'info', True)
|
|
||||||
else:
|
|
||||||
shutil.move(mobiPath + '_tostrip', mobiPath)
|
|
||||||
self.emit(QtCore.SIGNAL("addMessage"),
|
|
||||||
'KindleStrip failed to remove SRCS header!', 'warning')
|
|
||||||
self.emit(QtCore.SIGNAL("addMessage"),
|
|
||||||
'MOBI file will work correctly but it will be highly oversized.', 'warning')
|
|
||||||
else:
|
else:
|
||||||
os.remove(outputPath)
|
# ERROR: EPUB too big
|
||||||
if os.path.exists(outputPath.replace('.epub', '.mobi')):
|
self.kindlegenErrorCode = 23026
|
||||||
os.remove(outputPath.replace('.epub', '.mobi'))
|
except:
|
||||||
self.emit(QtCore.SIGNAL("addMessage"), 'KindleGen failed to create MOBI!', 'error')
|
# ERROR: Unknown generic error
|
||||||
self.emit(QtCore.SIGNAL("addMessage"), 'Try converting a smaller batch.', 'error')
|
self.kindlegenErrorCode = 1
|
||||||
else:
|
continue
|
||||||
excess = (os.path.getsize(outputPath) - 314572800)/1024/1024
|
if self.kindlegenErrorCode == 0:
|
||||||
|
self.emit(QtCore.SIGNAL("addMessage"), 'Creating MOBI file... Done!', 'info', True)
|
||||||
|
self.emit(QtCore.SIGNAL("addMessage"), 'Removing SRCS header...', 'info')
|
||||||
os.remove(outputPath)
|
os.remove(outputPath)
|
||||||
self.emit(QtCore.SIGNAL("addMessage"), 'Created EPUB file is too big for KindleGen!', 'error')
|
mobiPath = outputPath.replace('.epub', '.mobi')
|
||||||
self.emit(QtCore.SIGNAL("addMessage"), 'Limit exceeded by ' + str(excess) +
|
shutil.move(mobiPath, mobiPath + '_tostrip')
|
||||||
' MB. Try converting a smaller batch.', 'error')
|
try:
|
||||||
|
kindlestrip.main((mobiPath + '_tostrip', mobiPath))
|
||||||
|
except Exception:
|
||||||
|
self.errors = True
|
||||||
|
if not self.errors:
|
||||||
|
os.remove(mobiPath + '_tostrip')
|
||||||
|
self.emit(QtCore.SIGNAL("addMessage"), 'Removing SRCS header... Done!', 'info', True)
|
||||||
|
else:
|
||||||
|
shutil.move(mobiPath + '_tostrip', mobiPath)
|
||||||
|
self.emit(QtCore.SIGNAL("addMessage"),
|
||||||
|
'KindleStrip failed to remove SRCS header!', 'warning')
|
||||||
|
self.emit(QtCore.SIGNAL("addMessage"),
|
||||||
|
'MOBI file will work correctly but it will be highly oversized.', 'warning')
|
||||||
|
else:
|
||||||
|
epubSize = (os.path.getsize(outputPath))/1024/1024
|
||||||
|
os.remove(outputPath)
|
||||||
|
if os.path.exists(outputPath.replace('.epub', '.mobi')):
|
||||||
|
os.remove(outputPath.replace('.epub', '.mobi'))
|
||||||
|
self.emit(QtCore.SIGNAL("addMessage"), 'KindleGen failed to create MOBI!', 'error')
|
||||||
|
if self.kindlegenErrorCode == 1 and self.kindlegenError:
|
||||||
|
self.emit(QtCore.SIGNAL("showDialog"), "KindleGen error:\n\n" + self.kindlegenError)
|
||||||
|
if self.kindlegenErrorCode == 23026:
|
||||||
|
self.emit(QtCore.SIGNAL("addMessage"), 'Created EPUB file was too big.',
|
||||||
|
'error')
|
||||||
|
self.emit(QtCore.SIGNAL("addMessage"), 'EPUB file: ' + str(epubSize) + 'MB.'
|
||||||
|
' Supported size: ~300MB.', 'error')
|
||||||
self.emit(QtCore.SIGNAL("hideProgressBar"))
|
self.emit(QtCore.SIGNAL("hideProgressBar"))
|
||||||
self.parent.needClean = True
|
self.parent.needClean = True
|
||||||
self.emit(QtCore.SIGNAL("addMessage"), '<b>All jobs completed.</b>', 'info')
|
self.emit(QtCore.SIGNAL("addMessage"), '<b>All jobs completed.</b>', 'info')
|
||||||
|
|||||||
Reference in New Issue
Block a user