mirror of
https://github.com/ciromattia/kcc
synced 2025-12-22 14:11:45 +00:00
Fixed some file lock anomalies
This commit is contained in:
@@ -33,7 +33,7 @@ from distutils.version import StrictVersion
|
|||||||
from xml.sax.saxutils import escape
|
from xml.sax.saxutils import escape
|
||||||
from platform import platform
|
from platform import platform
|
||||||
from raven import Client
|
from raven import Client
|
||||||
from .shared import md5Checksum, HTMLStripper, sanitizeTrace
|
from .shared import md5Checksum, HTMLStripper, sanitizeTrace, saferRemove
|
||||||
from . import __version__
|
from . import __version__
|
||||||
from . import comic2ebook
|
from . import comic2ebook
|
||||||
from . import metadata
|
from . import metadata
|
||||||
@@ -331,7 +331,7 @@ class WorkerThread(QtCore.QThread):
|
|||||||
if 'outputPath' in locals():
|
if 'outputPath' in locals():
|
||||||
for item in outputPath:
|
for item in outputPath:
|
||||||
if os.path.exists(item):
|
if os.path.exists(item):
|
||||||
os.remove(item)
|
saferRemove(item)
|
||||||
self.clean()
|
self.clean()
|
||||||
return
|
return
|
||||||
if not self.errors:
|
if not self.errors:
|
||||||
@@ -358,9 +358,9 @@ class WorkerThread(QtCore.QThread):
|
|||||||
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):
|
||||||
os.remove(item)
|
saferRemove(item)
|
||||||
if os.path.exists(item.replace('.epub', '.mobi')):
|
if os.path.exists(item.replace('.epub', '.mobi')):
|
||||||
os.remove(item.replace('.epub', '.mobi'))
|
saferRemove(item.replace('.epub', '.mobi'))
|
||||||
self.clean()
|
self.clean()
|
||||||
return
|
return
|
||||||
if self.kindlegenErrorCode[0] == 0:
|
if self.kindlegenErrorCode[0] == 0:
|
||||||
@@ -381,7 +381,7 @@ class WorkerThread(QtCore.QThread):
|
|||||||
for item in outputPath:
|
for item in outputPath:
|
||||||
GUI.progress.content = ''
|
GUI.progress.content = ''
|
||||||
mobiPath = item.replace('.epub', '.mobi')
|
mobiPath = item.replace('.epub', '.mobi')
|
||||||
os.remove(mobiPath + '_toclean')
|
saferRemove(mobiPath + '_toclean')
|
||||||
if GUI.targetDirectory and GUI.targetDirectory != os.path.dirname(mobiPath):
|
if GUI.targetDirectory and GUI.targetDirectory != os.path.dirname(mobiPath):
|
||||||
try:
|
try:
|
||||||
move(mobiPath, GUI.targetDirectory)
|
move(mobiPath, GUI.targetDirectory)
|
||||||
@@ -399,9 +399,9 @@ class WorkerThread(QtCore.QThread):
|
|||||||
for item in outputPath:
|
for item in outputPath:
|
||||||
mobiPath = item.replace('.epub', '.mobi')
|
mobiPath = item.replace('.epub', '.mobi')
|
||||||
if os.path.exists(mobiPath):
|
if os.path.exists(mobiPath):
|
||||||
os.remove(mobiPath)
|
saferRemove(mobiPath)
|
||||||
if os.path.exists(mobiPath + '_toclean'):
|
if os.path.exists(mobiPath + '_toclean'):
|
||||||
os.remove(mobiPath + '_toclean')
|
saferRemove(mobiPath + '_toclean')
|
||||||
MW.addMessage.emit('Failed to process MOBI file!', 'error', False)
|
MW.addMessage.emit('Failed to process MOBI file!', 'error', False)
|
||||||
MW.addTrayMessage.emit('Failed to process MOBI file!', 'Critical')
|
MW.addTrayMessage.emit('Failed to process MOBI file!', 'Critical')
|
||||||
else:
|
else:
|
||||||
@@ -409,9 +409,9 @@ class WorkerThread(QtCore.QThread):
|
|||||||
epubSize = (os.path.getsize(self.kindlegenErrorCode[2])) // 1024 // 1024
|
epubSize = (os.path.getsize(self.kindlegenErrorCode[2])) // 1024 // 1024
|
||||||
for item in outputPath:
|
for item in outputPath:
|
||||||
if os.path.exists(item):
|
if os.path.exists(item):
|
||||||
os.remove(item)
|
saferRemove(item)
|
||||||
if os.path.exists(item.replace('.epub', '.mobi')):
|
if os.path.exists(item.replace('.epub', '.mobi')):
|
||||||
os.remove(item.replace('.epub', '.mobi'))
|
saferRemove(item.replace('.epub', '.mobi'))
|
||||||
MW.addMessage.emit('KindleGen failed to create MOBI!', 'error', False)
|
MW.addMessage.emit('KindleGen failed to create MOBI!', 'error', False)
|
||||||
MW.addTrayMessage.emit('KindleGen failed to create MOBI!', 'Critical')
|
MW.addTrayMessage.emit('KindleGen failed to create MOBI!', 'Critical')
|
||||||
if self.kindlegenErrorCode[0] == 1 and self.kindlegenErrorCode[1] != '':
|
if self.kindlegenErrorCode[0] == 1 and self.kindlegenErrorCode[1] != '':
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
walk = os.walk
|
walk = os.walk
|
||||||
from . import rarfile
|
from . import rarfile
|
||||||
from .shared import check7ZFile as is_7zfile, saferReplace
|
from .shared import check7ZFile as is_7zfile, saferReplace, saferRemove
|
||||||
|
|
||||||
|
|
||||||
class CBxArchive:
|
class CBxArchive:
|
||||||
@@ -66,7 +66,7 @@ class CBxArchive:
|
|||||||
for root, dirnames, filenames in walk(targetdir):
|
for root, dirnames, filenames in walk(targetdir):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if filename.startswith('__MACOSX') or filename.endswith('.DS_Store') or filename.endswith('humbs.db'):
|
if filename.startswith('__MACOSX') or filename.endswith('.DS_Store') or filename.endswith('humbs.db'):
|
||||||
os.remove(os.path.join(root, filename))
|
saferRemove(os.path.join(root, filename))
|
||||||
|
|
||||||
def extractCB7(self, targetdir):
|
def extractCB7(self, targetdir):
|
||||||
# Workaround for some wide UTF-8 + Popen abnormalities
|
# Workaround for some wide UTF-8 + Popen abnormalities
|
||||||
@@ -80,7 +80,7 @@ class CBxArchive:
|
|||||||
if b"Everything is Ok" in line:
|
if b"Everything is Ok" in line:
|
||||||
extracted = True
|
extracted = True
|
||||||
if sys.platform.startswith('darwin'):
|
if sys.platform.startswith('darwin'):
|
||||||
os.remove(self.origFileName)
|
saferRemove(self.origFileName)
|
||||||
if not extracted:
|
if not extracted:
|
||||||
raise OSError
|
raise OSError
|
||||||
|
|
||||||
|
|||||||
@@ -621,7 +621,7 @@ def getComicInfo(path, originalPath):
|
|||||||
try:
|
try:
|
||||||
xml = metadata.MetadataParser(xmlPath)
|
xml = metadata.MetadataParser(xmlPath)
|
||||||
except Exception:
|
except Exception:
|
||||||
os.remove(xmlPath)
|
saferRemove(xmlPath)
|
||||||
return
|
return
|
||||||
options.authors = []
|
options.authors = []
|
||||||
if defaultTitle:
|
if defaultTitle:
|
||||||
@@ -646,7 +646,7 @@ def getComicInfo(path, originalPath):
|
|||||||
options.chapters = xml.data['Bookmarks']
|
options.chapters = xml.data['Bookmarks']
|
||||||
if xml.data['Summary']:
|
if xml.data['Summary']:
|
||||||
options.summary = escape(xml.data['Summary'])
|
options.summary = escape(xml.data['Summary'])
|
||||||
os.remove(xmlPath)
|
saferRemove(xmlPath)
|
||||||
|
|
||||||
|
|
||||||
def getCoversFromMCB(mangaID):
|
def getCoversFromMCB(mangaID):
|
||||||
@@ -1168,14 +1168,14 @@ def makeBook(source, qtGUI=None):
|
|||||||
print('Error: Failed to tweak KindleGen output!')
|
print('Error: Failed to tweak KindleGen output!')
|
||||||
return filepath
|
return filepath
|
||||||
else:
|
else:
|
||||||
os.remove(i.replace('.epub', '.mobi') + '_toclean')
|
saferRemove(i.replace('.epub', '.mobi') + '_toclean')
|
||||||
if k.path and k.coverSupport:
|
if k.path and k.coverSupport:
|
||||||
options.covers[filepath.index(i)][0].saveToKindle(k, options.covers[filepath.index(i)][1])
|
options.covers[filepath.index(i)][0].saveToKindle(k, options.covers[filepath.index(i)][1])
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
|
|
||||||
def makeMOBIFix(item, uuid):
|
def makeMOBIFix(item, uuid):
|
||||||
os.remove(item)
|
saferRemove(item)
|
||||||
mobiPath = item.replace('.epub', '.mobi')
|
mobiPath = item.replace('.epub', '.mobi')
|
||||||
move(mobiPath, mobiPath + '_toclean')
|
move(mobiPath, mobiPath + '_toclean')
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from shutil import rmtree, copytree, move
|
|||||||
from optparse import OptionParser, OptionGroup
|
from optparse import OptionParser, OptionGroup
|
||||||
from multiprocessing import Pool
|
from multiprocessing import Pool
|
||||||
from PIL import Image, ImageStat, ImageOps
|
from PIL import Image, ImageStat, ImageOps
|
||||||
from .shared import getImageFileName, walkLevel, walkSort
|
from .shared import getImageFileName, walkLevel, walkSort, saferRemove
|
||||||
try:
|
try:
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -77,7 +77,7 @@ def mergeDirectory(work):
|
|||||||
img = ImageOps.fit(img, (targetWidth, img.size[1]), method=Image.BICUBIC, centering=(0.5, 0.5))
|
img = ImageOps.fit(img, (targetWidth, img.size[1]), method=Image.BICUBIC, centering=(0.5, 0.5))
|
||||||
result.paste(img, (0, y))
|
result.paste(img, (0, y))
|
||||||
y += img.size[1]
|
y += img.size[1]
|
||||||
os.remove(i)
|
saferRemove(i)
|
||||||
savePath = os.path.split(imagesValid[0])
|
savePath = os.path.split(imagesValid[0])
|
||||||
result.save(os.path.join(savePath[0], os.path.splitext(savePath[1])[0] + '.png'), 'PNG')
|
result.save(os.path.join(savePath[0], os.path.splitext(savePath[1])[0] + '.png'), 'PNG')
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -203,7 +203,7 @@ def splitImage(work):
|
|||||||
targetHeight += panels[panel][2]
|
targetHeight += panels[panel][2]
|
||||||
newPage.save(os.path.join(path, fileExpanded[0] + '-' + str(pageNumber) + '.png'), 'PNG')
|
newPage.save(os.path.join(path, fileExpanded[0] + '-' + str(pageNumber) + '.png'), 'PNG')
|
||||||
pageNumber += 1
|
pageNumber += 1
|
||||||
os.remove(filePath)
|
saferRemove(filePath)
|
||||||
except Exception:
|
except Exception:
|
||||||
return str(sys.exc_info()[1])
|
return str(sys.exc_info()[1])
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ def main(argv=None, qtGUI=None):
|
|||||||
pagenumber += 1
|
pagenumber += 1
|
||||||
work.append([root, name, options])
|
work.append([root, name, options])
|
||||||
else:
|
else:
|
||||||
os.remove(os.path.join(root, name))
|
saferRemove(os.path.join(root, name))
|
||||||
if GUI:
|
if GUI:
|
||||||
GUI.progressBarTick.emit('Splitting images')
|
GUI.progressBarTick.emit('Splitting images')
|
||||||
GUI.progressBarTick.emit(str(pagenumber))
|
GUI.progressBarTick.emit(str(pagenumber))
|
||||||
|
|||||||
Reference in New Issue
Block a user