mirror of
https://github.com/ciromattia/kcc
synced 2025-12-13 01:36:27 +00:00
Refactored detection of corrupted files
This commit is contained in:
@@ -712,9 +712,6 @@ def sanitizeTreeBeforeConversion(filetree):
|
||||
for root, dirs, files in os.walk(filetree, False):
|
||||
for name in files:
|
||||
os.chmod(os.path.join(root, name), stat.S_IWRITE | stat.S_IREAD)
|
||||
# Detect corrupted files - Phase 1
|
||||
if os.path.getsize(os.path.join(root, name)) == 0:
|
||||
os.remove(os.path.join(root, name))
|
||||
for name in dirs:
|
||||
os.chmod(os.path.join(root, name), stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
|
||||
|
||||
@@ -870,6 +867,25 @@ def preSplitDirectory(path):
|
||||
return [path]
|
||||
|
||||
|
||||
def detectCorruption(tmpPath, orgPath):
|
||||
for root, dirs, files in os.walk(tmpPath, False):
|
||||
for name in files:
|
||||
if getImageFileName(name) is not None:
|
||||
path = os.path.join(root, name)
|
||||
pathOrg = os.path.join(orgPath, name)
|
||||
if os.path.getsize(path) == 0:
|
||||
rmtree(os.path.join(tmpPath, '..', '..'), True)
|
||||
raise RuntimeError('Image file %s is corrupted.' % pathOrg)
|
||||
try:
|
||||
img = Image.open(path)
|
||||
img.verify()
|
||||
img = Image.open(path)
|
||||
img.load()
|
||||
except:
|
||||
rmtree(os.path.join(tmpPath, '..', '..'), True)
|
||||
raise RuntimeError('Image file %s is corrupted.' % pathOrg)
|
||||
|
||||
|
||||
def Copyright():
|
||||
print ('comic2ebook v%(__version__)s. '
|
||||
'Written 2013 by Ciro Mattia Gonano and Pawel Jastrzebski.' % globals())
|
||||
@@ -951,6 +967,7 @@ def main(argv=None, qtGUI=None):
|
||||
parser.print_help()
|
||||
return
|
||||
path = getWorkFolder(args[0])
|
||||
detectCorruption(path + "/OEBPS/Images/", args[0])
|
||||
checkComicInfo(path + "/OEBPS/Images/", args[0])
|
||||
if options.webtoon:
|
||||
if options.customheight > 0:
|
||||
|
||||
@@ -170,21 +170,6 @@ def splitImage(work):
|
||||
print ".",
|
||||
fileExpanded = os.path.splitext(name)
|
||||
filePath = os.path.join(path, name)
|
||||
# Detect corrupted files
|
||||
try:
|
||||
Image.open(filePath)
|
||||
except IOError:
|
||||
raise RuntimeError('Cannot read image file %s' % filePath)
|
||||
try:
|
||||
image = Image.open(filePath)
|
||||
image.verify()
|
||||
except:
|
||||
raise RuntimeError('Image file %s is corrupted' % filePath)
|
||||
try:
|
||||
image = Image.open(filePath)
|
||||
image.load()
|
||||
except:
|
||||
raise RuntimeError('Image file %s is corrupted' % filePath)
|
||||
image = Image.open(filePath)
|
||||
image = image.convert('RGB')
|
||||
widthImg, heightImg = image.size
|
||||
|
||||
17
kcc/image.py
17
kcc/image.py
@@ -122,26 +122,9 @@ class ComicPage:
|
||||
self.profile_label, self.size, self.palette, self.gamma, self.panelviewsize = device
|
||||
except KeyError:
|
||||
raise RuntimeError('Unexpected output device %s' % device)
|
||||
# Detect corrupted files - Phase 2
|
||||
try:
|
||||
self.origFileName = source
|
||||
self.filename = os.path.basename(self.origFileName)
|
||||
self.image = Image.open(source)
|
||||
except IOError:
|
||||
raise RuntimeError('Cannot read image file %s' % source)
|
||||
# Detect corrupted files - Phase 3
|
||||
try:
|
||||
self.image = Image.open(source)
|
||||
self.image.verify()
|
||||
except:
|
||||
raise RuntimeError('Image file %s is corrupted' % source)
|
||||
# Detect corrupted files - Phase 4
|
||||
try:
|
||||
self.image = Image.open(source)
|
||||
self.image.load()
|
||||
except:
|
||||
raise RuntimeError('Image file %s is corrupted' % source)
|
||||
self.image = Image.open(source)
|
||||
self.image = self.image.convert('RGB')
|
||||
self.rotated = None
|
||||
self.border = None
|
||||
|
||||
Reference in New Issue
Block a user