More exception handling for corrupt archives

git-svn-id: http://comictagger.googlecode.com/svn/trunk@326 6c5673fe-1810-88d6-992b-cd32ca31540c
This commit is contained in:
beville 2013-01-23 03:04:55 +00:00
parent 37048b99fc
commit 667c21bbed
2 changed files with 19 additions and 10 deletions

View File

@ -69,6 +69,8 @@ class ZipArchiver:
data = zf.read( archive_file )
except zipfile.BadZipfile:
print "bad zipfile: {0} :: {1}".format(self.path, archive_file)
except Exception:
print "bad zipfile: {0} :: {1}".format(self.path, archive_file)
finally:
zf.close()
return data
@ -288,6 +290,9 @@ class RarArchiver:
except (OSError, IOError) as e:
print e, "in readArchiveFile! try %s" % tries
time.sleep(1)
except Exception as e:
print "Unexpected exception in readArchiveFile! {0}".format( e )
break
else:
#Success"
@ -295,9 +300,9 @@ class RarArchiver:
if (len(entries) == 1):
return entries[0][1]
else:
return ""
return None
return ""
return None
@ -884,13 +889,17 @@ class ComicArchive:
if pil_available:
if 'ImageSize' not in p or 'ImageHeight' not in p or 'ImageWidth' not in p:
data = self.getPage( idx )
im = Image.open(StringIO.StringIO(data))
w,h = im.size
p['ImageSize'] = str(len(data))
p['ImageHeight'] = str(h)
p['ImageWidth'] = str(w)
if data is not None:
try:
im = Image.open(StringIO.StringIO(data))
w,h = im.size
p['ImageSize'] = str(len(data))
p['ImageHeight'] = str(h)
p['ImageWidth'] = str(w)
except IOError:
p['ImageSize'] = str(len(data))
else:
if 'ImageSize' not in p:
data = self.getPage( idx )

View File

@ -34,7 +34,7 @@ class ImageHasher(object):
image = self.image.resize((self.width, self.height), Image.ANTIALIAS).convert("L")
except Exception as e:
sys.exc_clear()
print "average_hash:", e.strerror
print "average_hash error:", e
return long(0)
pixels = list(image.getdata())