1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 09:46:25 +00:00

Fixed some file lock anomalies

This commit is contained in:
Paweł Jastrzębski
2016-11-21 17:24:58 +01:00
parent c68c9892e4
commit 284c577894
4 changed files with 20 additions and 20 deletions

View File

@@ -33,7 +33,7 @@ from distutils.version import StrictVersion
from xml.sax.saxutils import escape
from platform import platform
from raven import Client
from .shared import md5Checksum, HTMLStripper, sanitizeTrace
from .shared import md5Checksum, HTMLStripper, sanitizeTrace, saferRemove
from . import __version__
from . import comic2ebook
from . import metadata
@@ -331,7 +331,7 @@ class WorkerThread(QtCore.QThread):
if 'outputPath' in locals():
for item in outputPath:
if os.path.exists(item):
os.remove(item)
saferRemove(item)
self.clean()
return
if not self.errors:
@@ -358,9 +358,9 @@ class WorkerThread(QtCore.QThread):
if not self.conversionAlive:
for item in outputPath:
if os.path.exists(item):
os.remove(item)
saferRemove(item)
if os.path.exists(item.replace('.epub', '.mobi')):
os.remove(item.replace('.epub', '.mobi'))
saferRemove(item.replace('.epub', '.mobi'))
self.clean()
return
if self.kindlegenErrorCode[0] == 0:
@@ -381,7 +381,7 @@ class WorkerThread(QtCore.QThread):
for item in outputPath:
GUI.progress.content = ''
mobiPath = item.replace('.epub', '.mobi')
os.remove(mobiPath + '_toclean')
saferRemove(mobiPath + '_toclean')
if GUI.targetDirectory and GUI.targetDirectory != os.path.dirname(mobiPath):
try:
move(mobiPath, GUI.targetDirectory)
@@ -399,9 +399,9 @@ class WorkerThread(QtCore.QThread):
for item in outputPath:
mobiPath = item.replace('.epub', '.mobi')
if os.path.exists(mobiPath):
os.remove(mobiPath)
saferRemove(mobiPath)
if os.path.exists(mobiPath + '_toclean'):
os.remove(mobiPath + '_toclean')
saferRemove(mobiPath + '_toclean')
MW.addMessage.emit('Failed to process MOBI file!', 'error', False)
MW.addTrayMessage.emit('Failed to process MOBI file!', 'Critical')
else:
@@ -409,9 +409,9 @@ class WorkerThread(QtCore.QThread):
epubSize = (os.path.getsize(self.kindlegenErrorCode[2])) // 1024 // 1024
for item in outputPath:
if os.path.exists(item):
os.remove(item)
saferRemove(item)
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.addTrayMessage.emit('KindleGen failed to create MOBI!', 'Critical')
if self.kindlegenErrorCode[0] == 1 and self.kindlegenErrorCode[1] != '':

View File

@@ -27,7 +27,7 @@ try:
except ImportError:
walk = os.walk
from . import rarfile
from .shared import check7ZFile as is_7zfile, saferReplace
from .shared import check7ZFile as is_7zfile, saferReplace, saferRemove
class CBxArchive:
@@ -66,7 +66,7 @@ class CBxArchive:
for root, dirnames, filenames in walk(targetdir):
for filename in filenames:
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):
# Workaround for some wide UTF-8 + Popen abnormalities
@@ -80,7 +80,7 @@ class CBxArchive:
if b"Everything is Ok" in line:
extracted = True
if sys.platform.startswith('darwin'):
os.remove(self.origFileName)
saferRemove(self.origFileName)
if not extracted:
raise OSError

View File

@@ -621,7 +621,7 @@ def getComicInfo(path, originalPath):
try:
xml = metadata.MetadataParser(xmlPath)
except Exception:
os.remove(xmlPath)
saferRemove(xmlPath)
return
options.authors = []
if defaultTitle:
@@ -646,7 +646,7 @@ def getComicInfo(path, originalPath):
options.chapters = xml.data['Bookmarks']
if xml.data['Summary']:
options.summary = escape(xml.data['Summary'])
os.remove(xmlPath)
saferRemove(xmlPath)
def getCoversFromMCB(mangaID):
@@ -1168,14 +1168,14 @@ def makeBook(source, qtGUI=None):
print('Error: Failed to tweak KindleGen output!')
return filepath
else:
os.remove(i.replace('.epub', '.mobi') + '_toclean')
saferRemove(i.replace('.epub', '.mobi') + '_toclean')
if k.path and k.coverSupport:
options.covers[filepath.index(i)][0].saveToKindle(k, options.covers[filepath.index(i)][1])
return filepath
def makeMOBIFix(item, uuid):
os.remove(item)
saferRemove(item)
mobiPath = item.replace('.epub', '.mobi')
move(mobiPath, mobiPath + '_toclean')
try:

View File

@@ -24,7 +24,7 @@ from shutil import rmtree, copytree, move
from optparse import OptionParser, OptionGroup
from multiprocessing import Pool
from PIL import Image, ImageStat, ImageOps
from .shared import getImageFileName, walkLevel, walkSort
from .shared import getImageFileName, walkLevel, walkSort, saferRemove
try:
from PyQt5 import QtCore
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))
result.paste(img, (0, y))
y += img.size[1]
os.remove(i)
saferRemove(i)
savePath = os.path.split(imagesValid[0])
result.save(os.path.join(savePath[0], os.path.splitext(savePath[1])[0] + '.png'), 'PNG')
except Exception:
@@ -203,7 +203,7 @@ def splitImage(work):
targetHeight += panels[panel][2]
newPage.save(os.path.join(path, fileExpanded[0] + '-' + str(pageNumber) + '.png'), 'PNG')
pageNumber += 1
os.remove(filePath)
saferRemove(filePath)
except Exception:
return str(sys.exc_info()[1])
@@ -275,7 +275,7 @@ def main(argv=None, qtGUI=None):
pagenumber += 1
work.append([root, name, options])
else:
os.remove(os.path.join(root, name))
saferRemove(os.path.join(root, name))
if GUI:
GUI.progressBarTick.emit('Splitting images')
GUI.progressBarTick.emit(str(pagenumber))