mirror of
https://github.com/ciromattia/kcc
synced 2026-06-01 20:23:15 +00:00
Improved error handling
This commit is contained in:
+13
-8
@@ -430,16 +430,20 @@ class WorkerThread(QtCore.QThread):
|
|||||||
GUI.progress.content = ''
|
GUI.progress.content = ''
|
||||||
self.errors = True
|
self.errors = True
|
||||||
MW.addMessage.emit(str(warn), 'warning', False)
|
MW.addMessage.emit(str(warn), 'warning', False)
|
||||||
MW.addMessage.emit('Failed to create output file!', 'error', False)
|
MW.addMessage.emit('Error during conversion! Please consult '
|
||||||
MW.addTrayMessage.emit('Failed to create output file!', 'Critical')
|
'<a href="https://github.com/ciromattia/kcc/wiki/Error-messages">wiki</a> '
|
||||||
|
'for more details.', 'error', False)
|
||||||
|
MW.addTrayMessage.emit('Error during conversion!', 'Critical')
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
GUI.progress.content = ''
|
GUI.progress.content = ''
|
||||||
self.errors = True
|
self.errors = True
|
||||||
_, _, traceback = sys.exc_info()
|
_, _, traceback = sys.exc_info()
|
||||||
MW.showDialog.emit("Error during conversion %s:\n\n%s\n\nTraceback:\n%s"
|
MW.showDialog.emit("Error during conversion %s:\n\n%s\n\nTraceback:\n%s"
|
||||||
% (jobargv[-1], str(err), sanitizeTrace(traceback)), 'error')
|
% (jobargv[-1], str(err), sanitizeTrace(traceback)), 'error')
|
||||||
MW.addMessage.emit('Failed to create EPUB!', 'error', False)
|
MW.addMessage.emit('Error during conversion! Please consult '
|
||||||
MW.addTrayMessage.emit('Failed to create EPUB!', 'Critical')
|
'<a href="https://github.com/ciromattia/kcc/wiki/Error-messages">wiki</a> '
|
||||||
|
'for more details.', 'error', False)
|
||||||
|
MW.addTrayMessage.emit('Error during conversion!', 'Critical')
|
||||||
if not self.conversionAlive:
|
if not self.conversionAlive:
|
||||||
for item in outputPath:
|
for item in outputPath:
|
||||||
if os.path.exists(item):
|
if os.path.exists(item):
|
||||||
@@ -493,7 +497,7 @@ class WorkerThread(QtCore.QThread):
|
|||||||
GUI.progress.content = ''
|
GUI.progress.content = ''
|
||||||
mobiPath = item.replace('.epub', '.mobi')
|
mobiPath = item.replace('.epub', '.mobi')
|
||||||
os.remove(mobiPath + '_toclean')
|
os.remove(mobiPath + '_toclean')
|
||||||
if GUI.targetDirectory and GUI.targetDirectory != os.path.split(mobiPath)[0]:
|
if GUI.targetDirectory and GUI.targetDirectory != os.path.dirname(mobiPath):
|
||||||
try:
|
try:
|
||||||
move(mobiPath, GUI.targetDirectory)
|
move(mobiPath, GUI.targetDirectory)
|
||||||
mobiPath = os.path.join(GUI.targetDirectory, os.path.basename(mobiPath))
|
mobiPath = os.path.join(GUI.targetDirectory, os.path.basename(mobiPath))
|
||||||
@@ -529,7 +533,7 @@ class WorkerThread(QtCore.QThread):
|
|||||||
False)
|
False)
|
||||||
else:
|
else:
|
||||||
for item in outputPath:
|
for item in outputPath:
|
||||||
if GUI.targetDirectory and GUI.targetDirectory != os.path.split(item)[0]:
|
if GUI.targetDirectory and GUI.targetDirectory != os.path.dirname(item):
|
||||||
try:
|
try:
|
||||||
move(item, GUI.targetDirectory)
|
move(item, GUI.targetDirectory)
|
||||||
item = os.path.join(GUI.targetDirectory, os.path.basename(item))
|
item = os.path.join(GUI.targetDirectory, os.path.basename(item))
|
||||||
@@ -540,8 +544,9 @@ class WorkerThread(QtCore.QThread):
|
|||||||
GUI.progress.stop()
|
GUI.progress.stop()
|
||||||
MW.hideProgressBar.emit()
|
MW.hideProgressBar.emit()
|
||||||
GUI.needClean = True
|
GUI.needClean = True
|
||||||
MW.addMessage.emit('<b>All jobs completed.</b>', 'info', False)
|
if not self.errors:
|
||||||
MW.addTrayMessage.emit('All jobs completed.', 'Information')
|
MW.addMessage.emit('<b>All jobs completed.</b>', 'info', False)
|
||||||
|
MW.addTrayMessage.emit('All jobs completed.', 'Information')
|
||||||
MW.modeConvert.emit(1)
|
MW.modeConvert.emit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+26
-24
@@ -647,44 +647,38 @@ def imgFileProcessing(work):
|
|||||||
|
|
||||||
|
|
||||||
def getWorkFolder(afile):
|
def getWorkFolder(afile):
|
||||||
if len(afile) > 240:
|
|
||||||
raise UserWarning("Path is too long.")
|
|
||||||
if os.path.isdir(afile):
|
if os.path.isdir(afile):
|
||||||
workdir = mkdtemp('', 'KCC-')
|
workdir = mkdtemp('', 'KCC-')
|
||||||
try:
|
try:
|
||||||
os.rmdir(workdir)
|
os.rmdir(workdir)
|
||||||
fullPath = os.path.join(workdir, 'OEBPS', 'Images')
|
fullPath = os.path.join(workdir, 'OEBPS', 'Images')
|
||||||
if len(fullPath) > 240:
|
|
||||||
raise UserWarning("Path is too long.")
|
|
||||||
copytree(afile, fullPath)
|
copytree(afile, fullPath)
|
||||||
sanitizePermissions(fullPath)
|
sanitizePermissions(fullPath)
|
||||||
return workdir
|
return workdir
|
||||||
except OSError:
|
except:
|
||||||
rmtree(workdir, True)
|
rmtree(workdir, True)
|
||||||
raise
|
raise UserWarning("Failed to prepare a workspace.")
|
||||||
elif afile.lower().endswith('.pdf'):
|
elif afile.lower().endswith('.pdf'):
|
||||||
pdf = pdfjpgextract.PdfJpgExtract(afile)
|
pdf = pdfjpgextract.PdfJpgExtract(afile)
|
||||||
path, njpg = pdf.extract()
|
path, njpg = pdf.extract()
|
||||||
if njpg == 0:
|
if njpg == 0:
|
||||||
rmtree(path, True)
|
rmtree(path, True)
|
||||||
raise UserWarning("Failed to extract images.")
|
raise UserWarning("Failed to extract images from PDF file.")
|
||||||
else:
|
else:
|
||||||
workdir = mkdtemp('', 'KCC-')
|
workdir = mkdtemp('', 'KCC-')
|
||||||
cbx = cbxarchive.CBxArchive(afile)
|
cbx = cbxarchive.CBxArchive(afile)
|
||||||
if cbx.isCbxFile():
|
if cbx.isCbxFile():
|
||||||
try:
|
try:
|
||||||
path = cbx.extract(workdir)
|
path = cbx.extract(workdir)
|
||||||
except OSError:
|
except:
|
||||||
rmtree(workdir, True)
|
rmtree(workdir, True)
|
||||||
raise UserWarning("Failed to extract file.")
|
raise UserWarning("Failed to extract archive.")
|
||||||
else:
|
else:
|
||||||
rmtree(workdir, True)
|
rmtree(workdir, True)
|
||||||
raise TypeError("Failed to detect archive format.")
|
raise UserWarning("Failed to detect archive format.")
|
||||||
if len(os.path.join(path, 'OEBPS', 'Images')) > 240:
|
newpath = mkdtemp('', 'KCC-')
|
||||||
raise UserWarning("Path is too long.")
|
move(path, os.path.join(newpath, 'OEBPS', 'Images'))
|
||||||
move(path, path + "_temp")
|
return newpath
|
||||||
move(path + "_temp", os.path.join(path, 'OEBPS', 'Images'))
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
def getOutputFilename(srcpath, wantedname, ext, tomeNumber):
|
def getOutputFilename(srcpath, wantedname, ext, tomeNumber):
|
||||||
@@ -841,13 +835,6 @@ def sanitizePermissions(filetree):
|
|||||||
os.chmod(os.path.join(root, name), S_IWRITE | S_IREAD | S_IEXEC)
|
os.chmod(os.path.join(root, name), S_IWRITE | S_IREAD | S_IEXEC)
|
||||||
|
|
||||||
|
|
||||||
def sanitizeTemp():
|
|
||||||
for root, dirs, _ in walkLevel(gettempdir(), 0):
|
|
||||||
for tempdir in dirs:
|
|
||||||
if tempdir.startswith('KCC-'):
|
|
||||||
rmtree(os.path.join(root, tempdir), True)
|
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnboundLocalVariable
|
# noinspection PyUnboundLocalVariable
|
||||||
def splitDirectory(path):
|
def splitDirectory(path):
|
||||||
# Detect directory stucture
|
# Detect directory stucture
|
||||||
@@ -1046,7 +1033,7 @@ def createNewTome():
|
|||||||
|
|
||||||
def slugify(value):
|
def slugify(value):
|
||||||
value = slugifyExt(value)
|
value = slugifyExt(value)
|
||||||
value = sub(r'0*([0-9]{4,})', r'\1', sub(r'([0-9]+)', r'0000\1', value))
|
value = sub(r'0*([0-9]{4,})', r'\1', sub(r'([0-9]+)', r'0000\1', value, count=2))
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
@@ -1215,6 +1202,21 @@ def checkTools(source):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def checkPre(source):
|
||||||
|
# Make sure that all temporary files are gone
|
||||||
|
for root, dirs, _ in walkLevel(gettempdir(), 0):
|
||||||
|
for tempdir in dirs:
|
||||||
|
if tempdir.startswith('KCC-'):
|
||||||
|
rmtree(os.path.join(root, tempdir), True)
|
||||||
|
# Make sure that target directory is writable
|
||||||
|
if os.path.isdir(source):
|
||||||
|
writable = os.access(os.path.abspath(os.path.join(source, '..')), os.W_OK)
|
||||||
|
else:
|
||||||
|
writable = os.access(os.path.dirname(source), os.W_OK)
|
||||||
|
if not writable:
|
||||||
|
raise UserWarning("Target directory is not writable.")
|
||||||
|
|
||||||
|
|
||||||
def makeBook(source, qtGUI=None):
|
def makeBook(source, qtGUI=None):
|
||||||
"""Generates MOBI/EPUB/CBZ comic ebook from a bunch of images."""
|
"""Generates MOBI/EPUB/CBZ comic ebook from a bunch of images."""
|
||||||
global GUI
|
global GUI
|
||||||
@@ -1223,7 +1225,7 @@ def makeBook(source, qtGUI=None):
|
|||||||
GUI.progressBarTick.emit('1')
|
GUI.progressBarTick.emit('1')
|
||||||
else:
|
else:
|
||||||
checkTools(source)
|
checkTools(source)
|
||||||
sanitizeTemp()
|
checkPre(source)
|
||||||
path = getWorkFolder(source)
|
path = getWorkFolder(source)
|
||||||
print("\nChecking images...")
|
print("\nChecking images...")
|
||||||
getComicInfo(os.path.join(path, "OEBPS", "Images"), source)
|
getComicInfo(os.path.join(path, "OEBPS", "Images"), source)
|
||||||
|
|||||||
+1
-1
@@ -509,4 +509,4 @@ class Cover:
|
|||||||
try:
|
try:
|
||||||
self.image.save(self.target, "JPEG", optimize=1, quality=80)
|
self.image.save(self.target, "JPEG", optimize=1, quality=80)
|
||||||
except IOError:
|
except IOError:
|
||||||
raise RuntimeError('Failed to save cover')
|
raise RuntimeError('Failed to process downloaded cover.')
|
||||||
|
|||||||
Reference in New Issue
Block a user